vBulletin Search Engine Optimization
| |||||||
| Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| ||||
| On Wed, 16 Feb 2005, Todd C. Miller wrote: > In message <20050216230336.GA13132@petunia.outback.escape.d e> > so spake Matthias Kilian (kili): > > > I suggest to watch out for inappropriate or potentially breakable > > sizeof(TYPE) constructs in the code that can be replaced by > > sizeof(VAR). > > In general this is a good idea, though beware that using sizeof(pointer) > when you really want sizeof(*pointer) is also a common error. Another typical wrong use of sizeof: void f(char *p, size_t sz, char q[SOME_CONSTANT]) { memset(p, 0, sz); memset(q, 0, sizeof(q)); } Also, beware of code that was originally written using a fixed size array, and later changed to use malloc(): int *p; p = malloc(sz * sizeof(*p)); if (p == NULL) err(1, NULL); great, the developer wasn't lazy and is testing the return value of malloc(), but further down he messes up: memset(p, 0, sizeof(p)); Now the "nice" thing is that this can go undetected for a long time, since memory tends to contain quite some zeroes... -Otto |