Posted Mar 6, 2007 0:50 UTC (Tue) by ldo
In reply to: bad taste
Parent article: Quote of the week
Back in my Mac programming days (pre-OS-X), the APIs were full of "Pascal"-format strings, which started with a length byte. A maximum length of 255 may not sound like much, but I estimated that over 90% of the string objects in my programs fitted quite comfortably into this limit.
One thing, I was always careful to pass maximum buffer lengths. To reduce the chance of mistakes, I used macros like this:
#define Descr(v) (void *)&v, sizeof v
which I would use like this:
That way, if the destination buffer was too small for the string, the worst that would happen was that it was truncated--you would never get overwriting of random memory.
to post comments)