Skip to content

Commit d0303c1

Browse files
committed
multiple [u]int64_t parameters usage fix
1 parent 0a94df5 commit d0303c1

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

pg/driver.c

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,13 @@ static void
293293
lua_parse_param(struct lua_State *L,
294294
int idx, const char **value, int *length, Oid *type)
295295
{
296+
static char buf[512]; // buffer for serialized decimals
297+
static char *pos;
298+
if (idx == 5) { // lua_parse_param(L, idx + 5, ...
299+
*buf = '\0';
300+
pos = buf;
301+
}
302+
296303
if (lua_isnil(L, idx)) {
297304
*value = NULL;
298305
*length = 0;
@@ -320,20 +327,20 @@ lua_parse_param(struct lua_State *L,
320327
if (luaL_iscdata(L, idx)) {
321328
uint32_t ctypeid = 0;
322329
void *cdata = luaL_checkcdata(L, idx, &ctypeid);
323-
static char buf[24];
324330
int len = 0;
325331
if (ctypeid == luaL_ctypeid(L, "int64_t")) {
326-
len = snprintf(buf, sizeof(buf), "%ld", *(int64_t*)cdata);
332+
len = snprintf(pos, sizeof(buf) - (pos - buf), "%ld", *(int64_t*)cdata);
327333
*type = INT8OID;
328334
}
329335
else if (ctypeid == luaL_ctypeid(L, "uint64_t")) {
330-
len = snprintf(buf, sizeof(buf), "%lu", *(uint64_t*)cdata);
336+
len = snprintf(pos, sizeof(buf) - (pos - buf), "%lu", *(uint64_t*)cdata);
331337
*type = NUMERICOID;
332338
}
333339

334340
if (len > 0) {
335-
*value = buf;
341+
*value = pos;
336342
*length = len;
343+
pos += len + 1;
337344
return;
338345
}
339346
}

0 commit comments

Comments
 (0)