Skip to content

Commit c471a74

Browse files
committed
minor fixes to merge in
1 parent d1a9e81 commit c471a74

File tree

2 files changed

+21
-12
lines changed

2 files changed

+21
-12
lines changed

cunit/util.testc

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#include "util.h"
33
#include <malloc.h>
44

5-
extern char *xsyslog_ev_escape_value(const char *);
5+
extern const char *__test_xsyslog_ev_escape_value(struct buf *);
66
extern char __test_xsyslog_ev_guess_printf_escape(const char *);
77

88
static void test_xsyslog_ev_fmt(void)
@@ -97,13 +97,14 @@ static void test_xsyslog_ev_escape_value(void)
9797
};
9898

9999
unsigned i;
100+
struct buf in = BUF_INITIALIZER;
100101
for (i=0; test[i]; i += 2) {
101-
const char *in = test[i];
102+
buf_setcstr(&in, test[i]);
102103
const char *expected = test[i+1];
103-
char *actual = __test_xsyslog_ev_escape_value(in);
104+
const char *actual = __test_xsyslog_ev_escape_value(&in);
104105
CU_ASSERT_STRING_EQUAL(actual, expected);
105-
free(actual);
106106
};
107+
buf_free(&in);
107108
}
108109

109110
static void test_xsyslog_ev_guess_printf_escape(void)
@@ -163,9 +164,10 @@ static void test_xsyslog_ev_guess_printf_escape(void)
163164
const char *in = test[i];
164165
const char *expected = test[i+1];
165166
char actual = __test_xsyslog_ev_guess_printf_escape(in);
166-
if (actual != *expected) fprintf(stderr, "%s -> %c ? s/b %c \n", in, actual, *expected);
167+
if (actual != *expected) fprintf(stderr, "%s -> %c ? s/b %c (%hd) \n", in, actual, *expected, *expected);
167168
CU_ASSERT_EQUAL(actual, expected[0]);
168169
}
169170
}
170171

171172

173+

lib/util.c

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2194,8 +2194,9 @@ EXPORTED void xsyslog_fn(int priority, const char *description,
21942194
errno = saved_errno;
21952195
}
21962196

2197-
static char *xsyslog_ev_escape_value(struct buf *);
2198-
static void xsyslog_ev_fmt_skip_va(const char*, va_list);
2197+
static const char *xsyslog_ev_escape_value(struct buf *);
2198+
static void xsyslog_ev_fmt_skip_va(const char *, va_list);
2199+
static char *xsyslog_ev_fmt_va(const char *, va_list);
21992200
static char xsyslog_ev_guess_printf_escape(const char *);
22002201

22012202
/* xsyslog_ev:
@@ -2349,8 +2350,8 @@ static void xsyslog_ev_fmt_skip_va(const char* fmt, va_list ap)
23492350
case 'd': (void) va_arg(ap, int); break;
23502351
case 'l': (void) va_arg(ap, long); break;
23512352
case 'f': (void) va_arg(ap, double); break;
2352-
case 's': (void) va_arg(ap, (char *)); break;
2353-
case 'p': (void) va_arg(ap, (void *)); break;
2353+
case 's': (void) va_arg(ap, char *); break;
2354+
case 'p': (void) va_arg(ap, void *); break;
23542355
case 0:
23552356
// we could handle this by skipping the va_arg call entirely, which would allow the user to write
23562357
// xsyslog_ev(..., key, "foo", ...)
@@ -2380,8 +2381,9 @@ static void xsyslog_ev_fmt_skip_va(const char* fmt, va_list ap)
23802381
static char xsyslog_ev_guess_printf_escape(const char *s) {
23812382
unsigned is_long = 0;
23822383
TOP:
2383-
while (*s++ != '%') ; // seek past first % sign
2384-
if (!*s) return 0;
2384+
while (*s && *s != '%') s++; // seek to first % sign or to end of string
2385+
if (*s == 0) return 0; // String has no percent signs at all
2386+
s++;
23852387
if (*s == '%') { s++; goto TOP; } // it's "%%", skip it and continue
23862388

23872389
switch (*s) { // skip optional flag
@@ -2395,7 +2397,7 @@ static char xsyslog_ev_guess_printf_escape(const char *s) {
23952397
if (*s == 'l') { is_long++; s++; }
23962398
switch (*s) {
23972399
case 'd': case 'i': case '0': case 'u':
2398-
case 'x': case 'X': case 'c':
2400+
case 'x': case 'X': case 'c': case 'o':
23992401
return is_long ? 'l' : 'd';
24002402

24012403
case 'e': case 'E': case 'f': case 'F':
@@ -2508,3 +2510,8 @@ static const char *xsyslog_ev_escape_value(struct buf *val)
25082510

25092511
return buf_cstring(val);
25102512
}
2513+
2514+
EXPORTED const char *__test_xsyslog_ev_escape_value(struct buf *val)
2515+
{
2516+
return xsyslog_ev_escape_value(val);
2517+
}

0 commit comments

Comments
 (0)