On Sat, Mar 8, 2014 at 1:25 PM, Zsbán Ambrus <amb...@math.bme.hu> wrote:
> In the sqlite3 console, the following very simple statement gives > "Error: out of memory": > > SELECT char(); > > I think this is a bug. This query should need very little memory, so > it should not give such an error. I believe it should return a single > row with a single value of an empty string. > It isn't really running out of memory.... The implementation of char() allocates 4 bytes of output buffer for each input character, which is sufficient to hold any valid unicode codepoint. But with zero input characters, that means it tries to allocate a zero-byte output buffer. sqlite3_malloc() returns NULL when asked to allocate zero bytes, at which point the char() implementation thinks that the malloc() failed and reports the output-of-memory error. The fix is to allocate 4*N+1 bytes instead of 4*N bytes. Dan is checking in the fix even as I type this reply. -- D. Richard Hipp d...@sqlite.org _______________________________________________ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users