From: Martin Mares Date: Tue, 3 Sep 2013 13:48:23 +0000 (+0200) Subject: Opt: Tamed FIELD and LASTFIELD macros X-Git-Tag: v5.99~25^2~37 X-Git-Url: http://mj.ucw.cz/gitweb/?a=commitdiff_plain;h=bd6e38d572e2d8ef534d628328ff8dd92ddb3b6f;p=libucw.git Opt: Tamed FIELD and LASTFIELD macros They passed incorrect types to printf (ptrdiff_t instead of int) and evaluated strchrnul() repeatedly. --- 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