@@ -293,6 +293,13 @@ static void
293
293
lua_parse_param (struct lua_State * L ,
294
294
int idx , const char * * value , int * length , Oid * type )
295
295
{
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
+
296
303
if (lua_isnil (L , idx )) {
297
304
* value = NULL ;
298
305
* length = 0 ;
@@ -320,20 +327,20 @@ lua_parse_param(struct lua_State *L,
320
327
if (luaL_iscdata (L , idx )) {
321
328
uint32_t ctypeid = 0 ;
322
329
void * cdata = luaL_checkcdata (L , idx , & ctypeid );
323
- static char buf [24 ];
324
330
int len = 0 ;
325
331
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 );
327
333
* type = INT8OID ;
328
334
}
329
335
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 );
331
337
* type = NUMERICOID ;
332
338
}
333
339
334
340
if (len > 0 ) {
335
- * value = buf ;
341
+ * value = pos ;
336
342
* length = len ;
343
+ pos += len + 1 ;
337
344
return ;
338
345
}
339
346
}
0 commit comments