Hello, I was about to ask about allocating zero bytes, when I noticed this old question about the same thing...
So, basically, is there a reason why sqlite3Malloc(n) & co should even try to allocate zero bytes, instead of just returning NULL if n==0? Does a pointer pointing to zero bytes of memory have any use anyway? Mikio Kishi wrote: > Hi, > > Now, I'm developing some applications with "sqlite-3.0.8", > and also using "electric fence" which is a memory debugger. > (http://www.pf-lug.de/projekte/haya/efence.php) > > With the developed applications running, efectric fence detects a > memory error. To be more specific, malloc(0) may be invoked in > "sqlite3_exec()" function. > By default, electric fence detects malloc(0) as a memory error... > (EF_ALLOW_MALLOC_0 is true) > > > legacy.c (sqlite3_exec) > ---------------------------------------------------------------- > 71: azCols = sqliteMalloc(2*nCol*sizeof(const char *)); > ---------------------------------------------------------------- > > The above code is that (nCol may be 0). > > The result of malloc(0) is generally undefined. > (http://www.opengroup.org/onlinepubs/009695399/functions/malloc.html) > Are there any reason to invoke malloc(0) ? > > Sincerely, > > Mikio Kishi. > -- Lauri Nurmi Ksenos DVR Development