From: Bruno H. <br...@cl...> - 2017-03-23 20:16:16
|
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 |