Commit 1a160f7f authored by Hardy Simpson's avatar Hardy Simpson

bugfix: while sscanf, nread not initialised

parent b1411025
......@@ -341,8 +341,8 @@ exit:
/* section [global:1] [levels:2] [formats:3] [rules:4] */
static int zlog_conf_parse_line(zlog_conf_t * a_conf, char *line, int *section)
{
int nscan = 0;
int nread = 0;
int nscan;
int nread;
char name[MAXLEN_CFG_LINE + 1];
char word_1[MAXLEN_CFG_LINE + 1];
char word_2[MAXLEN_CFG_LINE + 1];
......@@ -426,6 +426,7 @@ static int zlog_conf_parse_line(zlog_conf_t * a_conf, char *line, int *section)
memset(word_1, 0x00, sizeof(word_1));
memset(word_2, 0x00, sizeof(word_2));
memset(word_3, 0x00, sizeof(word_3));
nread = 0;
nscan = sscanf(name, "%s%n%s%s", word_1, &nread, word_2, word_3);
if (STRCMP(word_1, ==, "strict") && STRCMP(word_2, ==, "init")) {
......
......@@ -86,6 +86,7 @@ zlog_format_t *zlog_format_new(char *line, int * time_cache_count)
* pattern %d(%F %X.%l) %-6V (%c:%F:%L) - %m%n
*/
memset(a_format->name, 0x00, sizeof(a_format->name));
nread = 0;
nscan = sscanf(line, " %[^= \t] = %n", a_format->name, &nread);
if (nscan != 1) {
zc_error("format[%s], syntax wrong", line);
......
......@@ -168,8 +168,9 @@ static zlog_file_t *zlog_file_check_new(zlog_rotater_t * a_rotater, const char *
goto err;
}
nread = 0;
nscan = sscanf(a_file->path + a_rotater->num_start_len, "%d%n", &(a_file->index), &(nread));
if (nscan == 0) nread = 0; /* if nothing is scaned, nread will be a random number */
/* if nothing is scaned, nread will be a random number */
if (a_rotater->num_width != 0) {
if (nread < a_rotater->num_width) {
......@@ -387,6 +388,7 @@ static int zlog_rotater_parse_archive_path(zlog_rotater_t * a_rotater)
return -1;
}
nread = 0;
sscanf(p, "#%d%n", &(a_rotater->num_width), &nread);
if (nread == 0) nread = 1;
if (*(p+nread) == 'r') {
......
......@@ -489,6 +489,7 @@ zlog_spec_t *zlog_spec_new(char *pattern_start, char **pattern_next, int *time_c
/* a string begin with %: %12.35d(%F %X,%l) */
/* process width and precision char in %-12.35P */
nread = 0;
nscan = sscanf(p, "%%%[.0-9-]%n", a_spec->print_fmt, &nread);
if (nscan == 1) {
a_spec->gen_msg = zlog_spec_gen_msg_reformat;
......@@ -518,8 +519,8 @@ zlog_spec_t *zlog_spec_new(char *pattern_start, char **pattern_next, int *time_c
strcpy(a_spec->time_fmt, ZLOG_DEFAULT_TIME_FMT);
p += 3;
} else {
nscan =
sscanf(p, "d(%[^)])%n", a_spec->time_fmt, &nread);
nread = 0;
nscan = sscanf(p, "d(%[^)])%n", a_spec->time_fmt, &nread);
if (nscan != 1) {
nread = 0;
}
......@@ -540,6 +541,7 @@ zlog_spec_t *zlog_spec_new(char *pattern_start, char **pattern_next, int *time_c
}
if (*p == 'M') {
nread = 0;
nscan = sscanf(p, "M(%[^)])%n", a_spec->mdc_key, &nread);
if (nscan != 1) {
nread = 0;
......
......@@ -96,14 +96,13 @@ int zc_str_replace_env(char *str, size_t str_size)
char env_value[MAXLEN_CFG_LINE + 1];
int str_len;
int env_value_len;
int nscan;
int nread;
str_len = strlen(str);
q = str;
do {
int nscan = 0;
int nread = 0;
p = strchr(q, '%');
if (!p) {
/* can't find more % */
......@@ -113,7 +112,7 @@ int zc_str_replace_env(char *str, size_t str_size)
memset(fmt, 0x00, sizeof(fmt));
memset(env_key, 0x00, sizeof(env_key));
memset(env_value, 0x00, sizeof(env_value));
nread = 0;
nscan = sscanf(p + 1, "%[.0-9-]%n", fmt + 1, &nread);
if (nscan == 1) {
fmt[0] = '%';
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment