News for hackers. Stuff that matters.
Re:Google paid a $250K reward for a bug by saagarjha on Monday August 11, 2025 @07:30AM (#44863017)
Programming is the consideration of implementation details. When you manipulate strings in C you consider the terminating nul byte just like when you manipulate strings in Python you consider how its stores codepoints or when you manipulate strings in Swift you think about grapheme clusters. There is no free lunch. (Though, of course, you can get reduced price lunches based on the choices you make!)
Re:Google paid a $250K reward for a bug by CrimsonCape on Tuesday August 12, 2025 @05:06PM (#44881814)
Pardon my ignorance, since I don't know C, but is it true to say that the length of string "Foo" is greater than 4 because of the null terminating byte? Or maybe there is no concept of string length? I could see this getting annoying since Foo is three chars long, you would assume it's length is 3, but we could be speaking of the actual length of bytes, in which i assume it is sizeof(char)*3+1 i.e. the sizeof(char F, char o, char o)+1nullbyte
Re:Google paid a $250K reward for a bug by probably_wrong on Thursday August 14, 2025 @05:44AM (#44898566)
The string length in C is "whatever number of bytes are there between the beginning of the string and the first \0 character". That's different from "how much memory is being used by this string" because you usually allocate a bigger buffer.

The length of the string "Foo", when properly terminated, is 3. The minimum number of bytes needed [1] to represent that string properly is 4 (3+'\0'). The actual number of bytes used by that string is whatever you asked for and received when using "malloc".

[1] Assuming ASCII and 1-byte characters.

Re:Google paid a $250K reward for a bug by saagarjha on Thursday August 14, 2025 @06:24AM (#44898781)
strlen("Foo") == 3 but you need 4 bytes to store it.