HardySimpson/zlog

Unreachable code for retval of zlog_conf_parse_line in conf.c

fortunely opened this issue · 0 comments

zlog_conf_parse_line() only return -1 or 0, so rc can never be a number > 0.

rc = zlog_conf_parse_line(a_conf, line, &section);
if (rc < 0) {
	zc_error("parse configure file[%s]line_no[%ld] fail", a_conf->file, line_no);
	zc_error("line[%s]", line);
	goto exit;
} else if (rc > 0) { /* unreachable code */
	...
}

src/conf.c L343
src/conf.c L372

UserGuilde mentions:

If "strict init = true”, zlog_init() will check syntax of all formats and rules strictly, and any error will cause zlog_init() to fail and return -1. When "strict init = false”, zlog_init() will ignore syntax errors for formats and rules. The default is true.

In function zlog_conf_parse_line(),

  1. if a_conf->strict_init == 1 (default value),
    when find out an error about global, levels, formats, rules, zlog would return -1 ;
  2. if a_conf->strict_init == 0,
    when find out an error, zlog would only log it by zc_error(), and ignore the line, and return 0 at last.

So i think there is a conflict in processing case 2).
Solution 1: in case 2), zlog_conf_parse_line() return 1, rather than ignoring it (return 0 at last).
Solution 2: remove if case: rc > 0, because zlog_conf_parse_line has ignored the error when strict_init == 0.