From bd6e38d572e2d8ef534d628328ff8dd92ddb3b6f Mon Sep 17 00:00:00 2001 From: Martin Mares Date: Tue, 3 Sep 2013 15:48:23 +0200 Subject: [PATCH] Opt: Tamed FIELD and LASTFIELD macros They passed incorrect types to printf (ptrdiff_t instead of int) and evaluated strchrnul() repeatedly. --- ucw/opt.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/ucw/opt.c b/ucw/opt.c index e2393ea0..d8e84a62 100644 --- a/ucw/opt.c +++ b/ucw/opt.c @@ -55,6 +55,11 @@ const struct opt_section * opt_section_root; #define FOREACHLINE(text) for (const char * begin = (text), * end = (text); (*end) && (end = strchrnul(begin, '\n')); begin = end+1) +static inline uns uns_min(uns x, uns y) +{ + return MIN(x, y); +} + void opt_help_internal(const struct opt_section * help) { int sections_cnt = 0; int lines_cnt = 0; @@ -148,8 +153,8 @@ void opt_help_internal(const struct opt_section * help) { #undef SPLITLINES s = 0; -#define FIELD(k) linelengths[k], MIN(strchrnul(lines[i][k], '\t')-lines[i][k],strchrnul(lines[i][k], '\n')-lines[i][k]), lines[i][k] -#define LASTFIELD(k) MIN(strchrnul(lines[i][k], '\t')-lines[i][k],strchrnul(lines[i][k], '\n')-lines[i][k]), lines[i][k] +#define FIELD(k) linelengths[k], uns_min(strchrnul(lines[i][k], '\t') - lines[i][k], strchrnul(lines[i][k], '\n') - lines[i][k]), lines[i][k] +#define LASTFIELD(k) uns_min(strchrnul(lines[i][k], '\t') - lines[i][k], strchrnul(lines[i][k], '\n') - lines[i][k]), lines[i][k] for (int i=0;i