std.file functions and embedded NUL characters [CWE-158]
monkyyy
crazymonkyyy at gmail.com
Fri Aug 1 01:13:21 UTC 2025
On Friday, 1 August 2025 at 00:48:36 UTC, Steven Schveighoffer
wrote:
> On Friday, 1 August 2025 at 00:22:20 UTC, monkyyy wrote:
>> On Friday, 1 August 2025 at 00:11:51 UTC, Steven Schveighoffer
>> wrote:
>>>
>>> If we checked for mid-string zero terminators on all calls to
>>> `toStringz`, we would kill performance where mostly it isn't
>>> necessary
>>
>> I bet the speed test is effectively a tie if its reasonably
>> written
>
> How do you "reasonably" write a linear search?
>
> Sure you can make it a faster O(n), but it's still O(n).
> Whereas just "add on a 0 if not there" is an O(1) operation.
>
> -Steve
Lets say you have a few paragraph of text that you split by \n
then you call toStringz to pass it to raylib(and you pay
attention to the immutablity of strings and not replace \n with
null)
You can do better with char arrays and different data structures
but the current api of the sorta maybe kinda dynamic array that
airnt special case chars, immutablity, and c liking null
termination all combine together to mean its probably making a
copy. During that copy you could check.
More information about the Digitalmars-d
mailing list