[sword-devel] swld.cpp at line 111 - is this a bug?

Manfred Bergmann manfred.bergmann at me.com
Thu Oct 13 11:56:47 MST 2016


> Am 13.10.2016 um 20:28 schrieb TS <outofthecube at icloud.com>:
>      Thank you all for your replies and confirmation. I will use the delete with the square brackets.

I would suggest to stick to the upstream code as much as possible. That means, have someone fix this in the main SWORD repo and pull a copy of it for PS.
Otherwise it’s hard to reason what exactly is used in PS.


>      I also had already looked at the Sword++ code and saw that it had the brackets which suggested to me that it was correct that something should be there.
>      I had some confusion because in Apple's ObjC framework, they also have a "new" function and Xcode was directing me to it when I was asking it to show me where "new" came.(The "new" use to created the variable which needed delete[]). As a result, I was uncertain as to how Xcode was implementing the code. I think though that it may be an error for Xcode to be directing me to the Cocoa definition of "new" since the file has the "cpp" file extension and so Xcode should know to expect c++ code. Also, "new" isn't being applied here in the code as a proper objective-c method call (I don't think?), so I'm thinking that it's being compiled as the "new" from the c++ library.
> Thanks again,    
> -TS
> On Oct 12, 2016, at 05:16 AM, DM Smith <dmsmith at crosswire.org> wrote:
>>> On Oct 12, 2016, at 3:22 AM, Jaak Ristioja <jaak at ristioja.ee <mailto:jaak at ristioja.ee>> wrote:
>>> On 12.10.2016 10:02, Manfred Bergmann wrote:
>>>>> Am 12.10.2016 um 08:57 schrieb Jaak Ristioja <jaak at ristioja.ee <mailto:jaak at ristioja.ee>>:
>>>>> On 12.10.2016 09:37, Manfred Bergmann wrote:
>>>>>>> On 12.10.2016 01:08, TS wrote:
>>>>>>>> Xcode was warning me that in PocketSword's Sword framework, swld.cpp at
>>>>>>>> line 111 with
>>>>>>>> "delete buf;"
>>>>>>>> may be wrong and it should perhaps be
>>>>>>>> "delete[] buf;"
>>>>>>>> instead. Is this correct? I looked at the code and I think Xcode is
>>>>>>>> correct in that the variable is an array and needs the brackets to
>>>>>>>> delete properly.
>>>>>>> Yes, Xcode has it correct. It should be `delete[] buf;`. This was also
>>>>>>> fixed in Sword++ in March.
>>>>>> Despite the warning, would but not be deleted completely?
>>>>> It is undefined behavior, as stated by § in C++11. However, the
>>>>> C++ draft at https://github.com/cplusplus/draft <https://github.com/cplusplus/draft> doesn't have this
>>>>> wording since e51a2152 [1] for some reason.
>>>> Yeah, don’t get me wrong. It should be corrected.
>>>> But is it indeed a memory leak or does the runtime still collect and destroy all array elements?
>>>> Depends on the runtime probably.
>>> It is undefined behavior (see http://stackoverflow.com/q/2397984/3919155 <http://stackoverflow.com/q/2397984/3919155>
>>> ). So as far as the C++ standard is concerned, this might yield
>>> different behavior depending on the toolchain, the runtime, the
>>> environment or the phase of the moon... There are also no defined bounds
>>> to what may happen: it may leak, crash, hang, corrupt memory, whatever...
>>> J
>> If I recall delete without the brackets will delete the object. That is the array. When called with the brackets will call delete on the elements in the array. In some cases the semantic difference does not matter, such as an array of char or int. I didn’t look at the code to see if it mattered here.
>> DM
>> _______________________________________________
>> sword-devel mailing list: sword-devel at crosswire.org <mailto:sword-devel at crosswire.org>
>> http://www.crosswire.org/mailman/listinfo/sword-devel <http://www.crosswire.org/mailman/listinfo/sword-devel>
>> Instructions to unsubscribe/change your settings at above page
> _______________________________________________
> sword-devel mailing list: sword-devel at crosswire.org
> http://www.crosswire.org/mailman/listinfo/sword-devel
> Instructions to unsubscribe/change your settings at above page

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.crosswire.org/pipermail/sword-devel/attachments/20161013/4a3cff5c/attachment-0001.html>

More information about the sword-devel mailing list