Skip to content

Commit

Permalink
fmt/print: improve print RE_VA_ARG debugging (#925)
Browse files Browse the repository at this point in the history
  • Loading branch information
sreimers authored Aug 30, 2023
1 parent 36b80da commit af26dea
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
4 changes: 1 addition & 3 deletions include/re_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -371,12 +371,10 @@ typedef int re_sock_t;
if (likely((safe))) { \
size_t sz = va_arg((ap), size_t); \
if (unlikely(!sz)) { \
re_assert(0 && "RE_VA_ARG: no more arguments"); \
err = EOVERFLOW; \
err = ENODATA; \
goto out; \
} \
if (unlikely(sz != sizeof(type))) { \
re_assert(0 && "RE_VA_ARG: arg is not compatible"); \
err = EOVERFLOW; \
goto out; \
} \
Expand Down
16 changes: 15 additions & 1 deletion src/fmt/print.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
* Copyright (C) 2010 Creytiv.com
*/
#include <string.h>
#include <math.h>
#include <re_types.h>
#include <re_sa.h>
#include <re_fmt.h>
#include <re_mem.h>
#include <math.h>
#ifdef _MSC_VER
#include <float.h>
#ifndef isinf
Expand All @@ -26,6 +26,9 @@
#define isnan(a) isnand((a))
#endif

#define DEBUG_MODULE "print"
#define DEBUG_LEVEL 5
#include <re_dbg.h>

enum length_modifier {
LENMOD_NONE = 0,
Expand Down Expand Up @@ -489,6 +492,17 @@ static int vhprintf(const char *fmt, va_list ap, re_vprintf_h *vph, void *arg,
err |= vph(p0, p - p0, arg);

out:
#ifndef RELEASE
if (err == ENODATA) {
DEBUG_WARNING("Format: \"%b<-- NO ARG\n", fmt, p - fmt + 1);
re_assert(0 && "RE_VA_ARG: no more arguments");
}
if (err == EOVERFLOW) {
DEBUG_WARNING("Format: \"%b<-- SIZE ERROR\n", fmt,
p - fmt + 1);
re_assert(0 && "RE_VA_ARG: arg is not compatible");
}
#endif
return err;
}

Expand Down

0 comments on commit af26dea

Please sign in to comment.