What every C Programmer should know about undefined behavior #2/3
Posted May 17, 2011 21:57 UTC (Tue) by baldridgeec (guest, #55283)
[Link]
For your last point, basically it comes down to "if there might be a \0 in valid input for this function, even though it may be a byte[], it is not a string."
So you use memchr() instead of strchr().
Or you use C++, and call it a string instead of a byte[]. (and use the actual C++ string-manipulation functions, not strchr - g++ warns about (byte[])string as being an invalid cast nowadays anyway though) :)
What every C Programmer should know about undefined behavior #2/3
Posted May 19, 2011 14:49 UTC (Thu) by dgm (subscriber, #49227)
[Link]
Your problem seems to be that you want to use the C string library to handle arrays of arbitrary bytes. I will not work, it's not what it was designed to do.
What every C Programmer should know about undefined behavior #2/3
Posted May 19, 2011 15:49 UTC (Thu) by stijn (subscriber, #570)
[Link]
Just to clarify, I can deal with both the string library and the mem functions. When I come to LWN, I hope to engage in constructive conversation, not chest-beating.