LWN.net Logo

bad taste

bad taste

Posted Mar 6, 2007 0:50 UTC (Tue) by ldo (subscriber, #40946)
In reply to: bad taste by k8to
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:

CopyString(Src, Descr(Dst));

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.


(Log in to post comments)

Copyright © 2013, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds