Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fmt/print: improve print RE_VA_ARG debugging #925

Merged
merged 1 commit into from
Aug 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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