Skip to content

Commit 3443047

Browse files
committed
Fix "RuntimeError: memory access out of bounds" bug
1 parent cf202fd commit 3443047

File tree

4 files changed

+23
-23
lines changed

4 files changed

+23
-23
lines changed

src/backend/access/common/printtup.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -499,9 +499,8 @@ StringInfoData json_result;
499499
EM_JS(void, dispatch_result, (char *res), {
500500
// Dispatch the result to JS land
501501
var query_result = UTF8ToString(res);
502-
out("dispatch_result: '" + query_result + "'");
503502
var event = new Module.Event("result", {
504-
detail: { result: JSON.parse(query_result) },
503+
detail: { result: query_result },
505504
});
506505
Module.eventTarget.dispatchEvent(event);
507506
});

src/backend/nodes/nodeFuncs.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4000,13 +4000,13 @@ planstate_tree_walker(PlanState *planstate,
40004000
/* Guard against stack overflow due to overly complex plan trees */
40014001
check_stack_depth();
40024002

4003-
printf("planstate_tree_walker1\n");
4003+
// printf("planstate_tree_walker1\n");
40044004

40054005
/* initPlan-s */
40064006
if (planstate_walk_subplans(planstate->initPlan, walker, context))
40074007
return true;
40084008

4009-
printf("planstate_tree_walker2\n");
4009+
// printf("planstate_tree_walker2\n");
40104010

40114011
/* lefttree */
40124012
if (outerPlanState(planstate))
@@ -4015,7 +4015,7 @@ planstate_tree_walker(PlanState *planstate,
40154015
return true;
40164016
}
40174017

4018-
printf("planstate_tree_walker3\n");
4018+
// printf("planstate_tree_walker3\n");
40194019

40204020
/* righttree */
40214021
if (innerPlanState(planstate))
@@ -4024,7 +4024,7 @@ planstate_tree_walker(PlanState *planstate,
40244024
return true;
40254025
}
40264026

4027-
printf("planstate_tree_walker4\n");
4027+
// printf("planstate_tree_walker4\n");
40284028

40294029
/* special child plans */
40304030
switch (nodeTag(plan))

src/backend/storage/smgr/md.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -746,8 +746,8 @@ mdwrite(SMgrRelation reln, ForkNumber forknum, BlockNumber blocknum,
746746
errhint("Check free disk space.")));
747747
}
748748

749-
printf("! writing block %u in file \"%s\"\n",
750-
blocknum, FilePathName(v->mdfd_vfd));
749+
// printf("! writing block %u in file \"%s\"\n",
750+
// blocknum, FilePathName(v->mdfd_vfd));
751751

752752
if (!skipFsync && !SmgrIsTemp(reln))
753753
register_dirty_segment(reln, forknum, v);

src/backend/tcop/postgres.c

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -347,38 +347,39 @@ interactive_getc(void)
347347
*
348348
* ----------------
349349
*/
350+
351+
#ifdef EMSCRIPTEN
350352
EM_ASYNC_JS(char *, await_query, (), {
351353
// Await a query from JS land
352-
out("await_query: waiting");
353354
var event = new Module.Event("waiting");
354355
Module.eventTarget.dispatchEvent(event);
355-
var { query, qtype } = await new Promise((resolve, reject) => {
356+
var query = await new Promise((resolve, reject) => {
356357
Module.eventTarget.addEventListener("query", (e) => {
357358
resolve(e.detail);
358359
}, {once: true});
359360
});
360-
query = query === undefined ? '' : query;
361-
qtype = qtype === undefined ? 'Q' : qtype;
362-
out("await_query: got '" + query + "' with type '" + qtype + "'");
363-
var combined = qtype + query; // Prepend qtype to query
364-
var combined_len = (query.length << 2) + 1;
365-
var cstring_ptr = stackAlloc(combined_len);
366-
stringToUTF8(combined, cstring_ptr, combined_len);
361+
var cstring_ptr = allocateUTF8(query);
367362
return cstring_ptr;
368363
});
364+
#endif
369365

370366
static int
371367
EmscriptenBackend(StringInfo inBuf)
372368
{
373-
char *combined = await_query();
374-
char qtype = *combined; // First character is qtype
369+
char *query = await_query();
370+
char qtype = *query; // First character is qtype
371+
int qlen = strlen(query);
375372

376373
resetStringInfo(inBuf);
377-
inBuf->data = combined + 1; // Skip qtype character
378-
inBuf->len = strlen(inBuf->data);
379-
appendStringInfoChar(inBuf, (char) '\0');
374+
if (qlen > 1)
375+
{
376+
appendBinaryStringInfoNT(inBuf, query + 1, qlen - 1);
377+
appendStringInfoChar(inBuf, (char) '\0');
378+
}
379+
380+
free(query);
380381

381-
return 'Q';
382+
return qtype;
382383
}
383384

384385
/* ----------------

0 commit comments

Comments
 (0)