lunarmodules / luasql

LuaSQL is a simple interface from Lua to a DBMS.
http://lunarmodules.github.io/luasql
539 stars 191 forks source link

ls_postgres.c #42

Closed emayo closed 8 years ago

emayo commented 8 years ago

I'm able to build Lua and LuaSQL with Embarcadero C++ Builder Rad Studio but had to make the following code modification to ls_postgres.c

The offending line, because len is not constant is not legal code. I imagine some compilers just deal with it. char to[len * sizeof(char) * 2 +1];

/ * Escapes a string for use within an SQL statement. * Returns a string with the escaped string. _/ static int conn_escape (lua_State L) { int rval = 0; conn_data conn = getconnection (L); size_t len; const char from = luaL_checklstring (L, 2, &len); const size_t tolen = len * sizeof(char) * 2 + 1; char to = malloc(tolen); int error; len = PQescapeStringConn (conn->pgconn, to, from, len, &error); if (error == 0) { / success ! / lua_pushlstring (L, to, len); rval = 1; } else rval = luasql_failmsg (L, "cannot escape string. PostgreSQL: ", PQerrorMessage (conn->pg_conn));

free(to); return(rval); }

echiesse commented 8 years ago

Can't believe this. Check this out: https://github.com/keplerproject/luasql/pull/13 (23 Nov 2013)

hishamhm commented 8 years ago

@echiesse, LuaSQL suffers from the lack of active maintainers. I'm not one of them, but since I have access to the repo I receive the notification emails, and I try to help out a bit when I can.

Back in 2013, I saw your PR, gave it a quick look, noted that the indentation was incorrect, posted a message and forgot about it. You never fixed the indentation in the PR or sent a reply, so the PR just sat there. If you had, I would have probably seen it and pressed the "Merge" button.

echiesse commented 8 years ago

Done.

I know you're not the responsible for this issue. In fact, I think you do a nice job maintaining LuaRocks. And in the middle of the discution about "out of memory safety" I completely lost your comment. The maintainer at that time told he would analyse the issue in order to come up with a better approach in case of an exception. And I then mostly lost track of it.

Well, it was just spaces vs tabs.

tomasguisasola commented 8 years ago

Hi

Sorry but that's not the correct way to implement, since Lua can longjump after malloc and before free, and you get a memory leak.

I'll correct that this weekend.

Regards, Tomás

On 2016-03-21 18:01, Eric Chiesse wrote:

Can't believe this. Check this out: #13 [1](23 Nov 2013)

You are receiving this because you are subscribed to this thread. Reply to this email directly or view it on GitHub [2]

*

Links:

[1] https://github.com/keplerproject/luasql/pull/13 [2] https://github.com/keplerproject/luasql/issues/42#issuecomment-199483158

tomasguisasola commented 8 years ago

The issue was corrected here in the repo and a new version (2.3.1) was uploaded to LuaRocks. Check that, please.