Skip to content

Commit

Permalink
Suppress warning -Wmaybe-uninitialized in pcre2_match.c
Browse files Browse the repository at this point in the history
When yielding we may store uninitialized variables
and we don't care.
  • Loading branch information
sverker committed Feb 3, 2025
1 parent c50592d commit 75181c5
Showing 1 changed file with 76 additions and 56 deletions.
132 changes: 76 additions & 56 deletions erts/emulator/pcre/pcre2_match.c
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,20 @@ edebug_printf(const char *format, ...)
fprintf(stderr, "\r\n");
}
#endif

#if !defined(__GNUC__) || defined(__e2k__)
# define ERTS_AT_LEAST_GCC_VSN__(MAJ, MIN, PL) 0
#elif !defined(__GNUC_MINOR__)
# define ERTS_AT_LEAST_GCC_VSN__(MAJ, MIN, PL) \
((__GNUC__ << 24) >= (((MAJ) << 24) | ((MIN) << 12) | (PL)))
#elif !defined(__GNUC_PATCHLEVEL__)
# define ERTS_AT_LEAST_GCC_VSN__(MAJ, MIN, PL) \
(((__GNUC__ << 24) | (__GNUC_MINOR__ << 12)) >= (((MAJ) << 24) | ((MIN) << 12) | (PL)))
#else
# define ERTS_AT_LEAST_GCC_VSN__(MAJ, MIN, PL) \
(((__GNUC__ << 24) | (__GNUC_MINOR__ << 12) | __GNUC_PATCHLEVEL__) >= (((MAJ) << 24) | ((MIN) << 12) | (PL)))
#endif

#endif

/*************************************************
Expand Down Expand Up @@ -6940,55 +6954,6 @@ match_block *mb = &actual_match_block;
mb->cb = &cb; \
} while (0)

#define SWAPOUT() do { \
if (exec_context == &internal_context) { \
exec_context = (PcreExecContext *) \
(match_data->memctl.malloc(sizeof(PcreExecContext), \
match_data->memctl.memory_data)); \
*(match_data->restart_data) = (void *) exec_context; \
*exec_context = internal_context; \
} \
exec_context->Xrc = rc; \
exec_context->Xwas_zero_terminated = was_zero_terminated; \
exec_context->Xstart_bits = start_bits; \
exec_context->Xre = re; \
exec_context->Xanchored = anchored; \
exec_context->Xfirstline = firstline; \
exec_context->Xhas_first_cu = has_first_cu; \
exec_context->Xhas_req_cu = has_req_cu; \
exec_context->Xstartline = startline; \
exec_context->Xmemchr_found_first_cu = memchr_found_first_cu; \
exec_context->Xmemchr_found_first_cu2 = memchr_found_first_cu2; \
exec_context->Xfirst_cu = first_cu; \
exec_context->Xfirst_cu2 = first_cu2; \
exec_context->Xreq_cu = req_cu; \
exec_context->Xreq_cu2 = req_cu2; \
exec_context->Xbumpalong_limit = bumpalong_limit; \
exec_context->Xend_subject = end_subject; \
exec_context->Xtrue_end_subject = true_end_subject; \
exec_context->Xstart_match = start_match; \
exec_context->Xreq_cu_ptr = req_cu_ptr; \
exec_context->Xstart_partial = start_partial; \
exec_context->Xmatch_partial = match_partial; \
exec_context->Xutf = utf; \
exec_context->Xucp = ucp; \
exec_context->Xallow_invalid = allow_invalid; \
exec_context->Xfragment_options = fragment_options; \
exec_context->Xframe_size = frame_size; \
exec_context->Xheapframes_size = heapframes_size; \
exec_context->Xcb = cb; \
/* Parameters */ \
exec_context->Xsubject = subject; \
exec_context->Xlength = length; \
exec_context->Xstart_offset = start_offset; \
exec_context->Xoptions = options; \
exec_context->Xmatch_data = match_data; \
exec_context->Xmcontext = mcontext; \
/* Adjust pointers */ \
exec_context->Xmb = &(exec_context->Xactual_match_block); \
exec_context->Xmb->cb = &(exec_context->Xcb); \
} while (0)

PcreExecContext *exec_context;
PcreExecContext internal_context;
int rc;
Expand Down Expand Up @@ -7377,8 +7342,7 @@ if (utf &&

#if defined(ERLANG_INTEGRATION)
if (match_data->rc == PCRE2_ERROR_UTF8_YIELD) {
SWAPOUT();
return PCRE2_ERROR_LOOP_LIMIT;
goto erlang_swapout;
}
#endif
/* Invalid UTF string. Adjust the offset to be an absolute offset in the
Expand Down Expand Up @@ -8005,13 +7969,69 @@ for(;;)
fprintf(stderr, "++ match() returned %d\n\n", rc);
#endif
#ifdef ERLANG_INTEGRATION
while(rc == PCRE2_ERROR_LOOP_LIMIT) {
EDEBUGF(("Loop limit break detected"));
SWAPOUT();
return PCRE2_ERROR_LOOP_LIMIT;
while(rc == PCRE2_ERROR_LOOP_LIMIT)
{
EDEBUGF(("Loop limit break detected"));
erlang_swapout:
if (exec_context == &internal_context)
{
exec_context = (PcreExecContext *)
(match_data->memctl.malloc(sizeof(PcreExecContext),
match_data->memctl.memory_data));
*(match_data->restart_data) = (void *) exec_context;
*exec_context = internal_context;
}
#if ERTS_AT_LEAST_GCC_VSN__(4, 7, 2)
# pragma GCC diagnostic push
# pragma GCC diagnostic ignored "-Wmaybe-uninitialized"
#endif
exec_context->Xrc = rc;
exec_context->Xwas_zero_terminated = was_zero_terminated;
exec_context->Xstart_bits = start_bits;
exec_context->Xre = re;
exec_context->Xanchored = anchored;
exec_context->Xfirstline = firstline;
exec_context->Xhas_first_cu = has_first_cu;
exec_context->Xhas_req_cu = has_req_cu;
exec_context->Xstartline = startline;
exec_context->Xmemchr_found_first_cu = memchr_found_first_cu;
exec_context->Xmemchr_found_first_cu2 = memchr_found_first_cu2;
exec_context->Xfirst_cu = first_cu;
exec_context->Xfirst_cu2 = first_cu2;
exec_context->Xreq_cu = req_cu;
exec_context->Xreq_cu2 = req_cu2;
exec_context->Xbumpalong_limit = bumpalong_limit;
exec_context->Xend_subject = end_subject;
exec_context->Xtrue_end_subject = true_end_subject;
exec_context->Xstart_match = start_match;
exec_context->Xreq_cu_ptr = req_cu_ptr;
exec_context->Xstart_partial = start_partial;
exec_context->Xmatch_partial = match_partial;
exec_context->Xutf = utf;
exec_context->Xucp = ucp;
exec_context->Xallow_invalid = allow_invalid;
exec_context->Xfragment_options = fragment_options;
exec_context->Xframe_size = frame_size;
exec_context->Xheapframes_size = heapframes_size;
exec_context->Xcb = cb;
#if ERTS_AT_LEAST_GCC_VSN__(4, 7, 2)
# pragma GCC diagnostic pop
#endif

/* Parameters */
exec_context->Xsubject = subject;
exec_context->Xlength = length;
exec_context->Xstart_offset = start_offset;
exec_context->Xoptions = options;
exec_context->Xmatch_data = match_data;
exec_context->Xmcontext = mcontext;
/* Adjust pointers */
exec_context->Xmb = &(exec_context->Xactual_match_block);
exec_context->Xmb->cb = &(exec_context->Xcb);
return PCRE2_ERROR_LOOP_LIMIT;
RESTART_INTERRUPTED:
rc = match(NULL,NULL,0,frame_size,match_data,mb);
}
}
mb->state_save = NULL; /* So that next call to free_saved... does not crash */
#endif

Expand Down

0 comments on commit 75181c5

Please sign in to comment.