From: Michal Bloch Date: Tue, 27 Nov 2018 10:11:23 +0000 (+0100) Subject: limiter: fix internal priority mapping X-Git-Tag: accepted/tizen/unified/20181130.064916~4 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=11c86b23ba1fe49d5440d9a4397231bb5fe89ccd;p=platform%2Fcore%2Fsystem%2Fdlog.git limiter: fix internal priority mapping Now makes sure the result is one of the chars "?*VDIWEFS". Previously it could return lowercase characters, numerical characters (except '8' which stands for SILENT but including '1' which stands for DEFAULT which is not a real priority), or the null character (when passed the integers 0 or 1). Change-Id: I3766d699e553d71265a979ababe59fccdd16d571 Signed-off-by: Michal Bloch --- diff --git a/src/libdlog/loglimiter.c b/src/libdlog/loglimiter.c index 7c02cfe..4d610bc 100644 --- a/src/libdlog/loglimiter.c +++ b/src/libdlog/loglimiter.c @@ -120,7 +120,10 @@ static int rule_match(struct rule* r1, unsigned key, const char* s, int prio) /* Translate fancy priority notation into common denominator */ static int util_prio_to_char(int prio) { + static const int NUM_CHAR_OFFSET = '0' - 0; static const char pri_table[DLOG_PRIO_MAX] = { + [DLOG_UNKNOWN] = '?', + [DLOG_DEFAULT] = '*', [DLOG_VERBOSE] = 'V', [DLOG_DEBUG] = 'D', [DLOG_INFO] = 'I', @@ -130,26 +133,35 @@ static int util_prio_to_char(int prio) [DLOG_SILENT] = 'S', }; - if (DLOG_PRIO_MAX > prio && prio >= 0) { + switch (prio) { + case 'V': + case 'D': + case 'I': + case 'W': + case 'E': + case 'F': + case 'S': + case '*': + return prio; + + case 'v': + case 'd': + case 'i': + case 'w': + case 'e': + case 'f': + case 's': + return toupper(prio); + + case '0' ... (DLOG_PRIO_MAX - 1 + NUM_CHAR_OFFSET): + return pri_table[prio - NUM_CHAR_OFFSET]; + + case 0 ... (DLOG_PRIO_MAX - 1): return pri_table[prio]; - } else { - switch (prio) { - case 'V': case 'v': case '1': - case 'D': case 'd': case '2': - case 'I': case 'i': case '3': - case 'W': case 'w': case '4': - case 'E': case 'e': case '5': - case 'F': case 'f': case '6': - case 'S': case 's': case '7': - case '*': - return prio; - - default: - ;; - } - } - return '?';// LCOV_EXCL_LINE + default: + return '?'; + } } /* The key is built from TAG and priority by DJB algorithm (Dan Bernstein).