Re: [sqlite] Out of memory error for SELECT char();
Eduardo Morras wrote: > On Sat, 8 Mar 2014 14:09:17 -0500 > Richard Hipp wrote: >> 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. > > It's OS dependant. From malloc FreeBSD man page [...] malloc() behavior wrt 0-byte allocation is OS-dependent. sqlite3_malloc() is not: it will return NULL on any OS, regardless of malloc() implementation. ___ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users
Re: [sqlite] Out of memory error for SELECT char();
On Sat, 8 Mar 2014 14:09:17 -0500 Richard Hipp wrote: > 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. It's OS dependant. From malloc FreeBSD man page, malloc.conf/_malloc_options, V option means: V Attempting to allocate zero bytes will return a NULL pointer instead of a valid pointer. (The default behavior is to make a minimal allocation and return a pointer to it.) This option is provided for System V compatibility. This option is incompatible with the ``X'' option. > > 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 --- --- Eduardo Morras ___ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users
Re: [sqlite] Out of memory error for SELECT char();
Hello, would be nicer to test N rather than guarding + 1UL size_t allocsize = 4 * N; if (!allocsize) { trigger(malformatted_sql_call_dumb_ass); // bail } Best Regards. On Sat, Mar 8, 2014 at 11:09 AM, Richard Hipp wrote: > On Sat, Mar 8, 2014 at 1:25 PM, Zsbán Ambrus 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 > ___ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users
Re: [sqlite] Out of memory error for SELECT char();
On 8-3-2014 19:48, Simon Slavin wrote: On 8 Mar 2014, at 6:25pm, Zsbán Ambrus wrote: In the sqlite3 console, the following very simple statement gives "Error: out of memory": SELECT char(); I think this is a bug. 162:~ simon$ sqlite3 ~/Desktop/test.sqlite SQLite version 3.7.13 2012-07-17 17:46:21 Enter ".help" for instructions Enter SQL statements terminated with a ";" sqlite> SELECT char(); Error: no such function: char sqlite> Could you please post your OS and the version of the SQLite shell tool you're using ? It happens on Windows 7 too: C:\temp>sqlite3 SQLite version 3.8.3.1 2014-02-11 14:52:19 Enter ".help" for instructions Enter SQL statements terminated with a ";" sqlite> select char(); Error: out of memory sqlite> select char(65); A sqlite> ___ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users
Re: [sqlite] Out of memory error for SELECT char();
On Sat, Mar 8, 2014 at 1:25 PM, Zsbán Ambrus 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
Re: [sqlite] Out of memory error for SELECT char();
On 03/09/2014 01:25 AM, Zsbán Ambrus wrote: In the sqlite3 console, the following very simple statement gives "Error: out of memory": SELECT char(); I think this is a bug. It is. Thanks for the report. Now fixed here: http://www.sqlite.org/src/info/ba39df9d4f Dan. 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. I've reproduced this in both a few days old preview sqlite-amalgamation-201403051440 and the stable sqlite3 3.8.1. Ambrus ___ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users ___ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users
Re: [sqlite] Out of memory error for SELECT char();
On 3/8/14, Simon Slavin wrote: > SQLite version 3.7.13 2012-07-17 17:46:21 The char function was added in 3.7.16. > Could you please post your OS and the version of the SQLite shell tool > you're using ? I'm using Linux amd64, compiling with gcc 4.8.1. I've got the out of memory result in both sqlite 3.8.1 and a few days old preview sqlite-amalgamation-201403051440. Ambrus ___ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users
Re: [sqlite] Out of memory error for SELECT char();
On 8 Mar 2014, at 6:25pm, Zsbán Ambrus wrote: > In the sqlite3 console, the following very simple statement gives > "Error: out of memory": > > SELECT char(); > > I think this is a bug. 162:~ simon$ sqlite3 ~/Desktop/test.sqlite SQLite version 3.7.13 2012-07-17 17:46:21 Enter ".help" for instructions Enter SQL statements terminated with a ";" sqlite> SELECT char(); Error: no such function: char sqlite> Could you please post your OS and the version of the SQLite shell tool you're using ? Simon. ___ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users
[sqlite] Out of memory error for SELECT char();
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. I've reproduced this in both a few days old preview sqlite-amalgamation-201403051440 and the stable sqlite3 3.8.1. Ambrus ___ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users