Peter Rosin skrev 2012-03-27 10:11: > But...careful! You have to assume that the original authors were not > idiots! Maybe the obvious strcmp was not used for a *good* reason? I > can't tell if d->meaningful is guaranteed to be zero-terminated from the > limited context, but it sure is suspect. Assuming that the original > authors were not idiots but instead made an off-by one error missing a > corner-case, the safer approach is to replace line 11 with: > > 11: if (!strncmp (d->meaningful, id->string, id->size + 1)) > > That is, if id->string is guaranteed to be zero-terminated, which is > not clear either, but perhaps easier to verify...
Scratch that, including the zero-terminator in the compare doesn't work as expected if one of the strings is not zero-terminated. But the point still stands, don't assume the original authors were idiots, and dig into the reasons for them to not having used strcmp from the start. Cheers, Peter -- Problem reports: http://cygwin.com/problems.html FAQ: http://cygwin.com/faq/ Documentation: http://cygwin.com/docs.html Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple