vBulletin Search Engine Optimization
| |||||||
| Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| ||||
| On Thu, Feb 17, 2005 at 09:09:44AM +0100, Otto Moerbeek wrote: [...] > > > 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. Sure. I didn't mean to hunt for *every* construct mentioned above -- there are thousands of pretty normal one-liners. The problem in the ksh example was the "lexical decoupling" of the buffer declaration and the parameter dictating the real bounds. > 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)); How much lines were there between the err() and the memset()? Both introduced errors (my ksh hack and your example) may have a similar smell: the developers were too lazy to scroll down to examine *every* use of the changed variable. Ciao, Kili ps: no need to CC: me, I'm subscribed to tech@ |
| Thread Tools | |
| Display Modes | |
|
|