Re: can DYNAMIC_ARRAY set its first argument to NULL?
Bruno Haible <[email protected]>
| Newsgroups | gmane.lisp.clisp.devel |
|---|---|
| Message-ID | <7272417.Qlhl4ThadK@omega> |
Hi Sam, > Can > > --8<---------------cut here---------------start------------->8--- > DYNAMIC_ARRAY(prompt,char,Sbvector_length(lastline)+1); > --8<---------------cut here---------------end--------------->8--- > > set prompt to NULL? Yes, this can happen if 1) we're not doing the allocation on the stack, and 2) malloca(), based on malloc(), fails - this happens when memory is tight. > everywhere else we seem to assume that it is non-NULL. Yuck. This may lead to crashes when memory is so tight that the OS will not give the process more memory. If you are going to fix this: The other - probably bigger - risk is that the allocation will be larger than the stack. That is, instead of arrayeltype arrayvar[arraysize] or arrayeltype* arrayvar = (arrayeltype*)alloca((arraysize)*sizeof(arrayeltype)) - which both the overflow the stack - we should *always* do arrayeltype* arrayvar = (arrayeltype*)malloca((arraysize)*sizeof(arrayeltype)) because it puts only small allocations on the stack. Bruno ------------------------------------------------------------------------------ Check out the vibrant tech community on one of the world's most engaging tech sites, Slashdot.org! http://sdm.link/slashdot _______________________________________________ clisp-devel mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/clisp-devel