> Fixed-size arrays are often (not always) bad. I usually try to malloc,

>From the consequent posts in this thread, I gather that people cite
buffer-overflows as a reason to avoid fixed size arrays. The idea
proposed is to malloc as much memory as the input is received
dynamically. 

To reiterate, buffer overflows are *logical* errors and may be caused by
faulty management of dynamic memory too. I would even say that dynamic
vs. static memory allocation vis-a-vis buffer overflows is a non-issue!
It's all governed by the needs of the program.

Like, in places where reading large chunks of data is required, the most
commonly used method is to allocate
block-sized buffers at once, fill them up and then allocate more
block-sized chunks or re-use the old buffer. (There's another neat
method given in the Dragon Book).

For things like names, or dates, one may use fixed size arrays, use
functions like snprintf(), fgets(), strncpy() instead of their 'non-n'
counterparts and do some bounds checking where these functions maybe
inadequate.

-- 
Tahir Hashmi (VSE, NCST)
http://staff.ncst.ernet.in/tahir
tahir AT ncst DOT ernet DOT in

We, the rest of humanity, wish GNU luck and Godspeed


_______________________________________________
http://mm.ilug-bom.org.in/mailman/listinfo/linuxers

Reply via email to