From a3b4e693fe28b3ac6aa1ec892661a61779a76ffe Mon Sep 17 00:00:00 2001 From: Chris Pockele Date: Sun, 8 Jan 2012 22:31:35 +0000 Subject: [PATCH] v4l-utils: ir-keytable file parsing errors MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit While configuring a remote control I noticed that the ir-keytable utility would throw the message "Invalid parameter on line 1" if the first line following the "table ... type: ..." line is a comment. Also, if a configuration line is invalid, the line number indication of the error message is sometimes incorrect, because the comments before it are not counted. This happens because of the "continue" statement when processing comments (or the table/type line), thus skipping the line counter increase at the end of the loop. The included patch fixes both problems by making sure the counter is always increased. The parse_cfgfile() function had a similar problem. Signed-off-by: Chris Pockelé Signed-off-by: Mauro Carvalho Chehab --- utils/keytable/keytable.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/utils/keytable/keytable.c b/utils/keytable/keytable.c index f03de26..a9119d7 100644 --- a/utils/keytable/keytable.c +++ b/utils/keytable/keytable.c @@ -202,9 +202,11 @@ static error_t parse_keyfile(char *fname, char **table) while (fgets(s, sizeof(s), fin)) { char *p = s; + + line++; while (*p == ' ' || *p == '\t') p++; - if (!line && p[0] == '#') { + if (line==1 && p[0] == '#') { p++; p = strtok(p, "\n\t =:"); do { @@ -279,7 +281,6 @@ static error_t parse_keyfile(char *fname, char **table) return ENOMEM; } nextkey = nextkey->next; - line++; } fclose(fin); @@ -287,7 +288,7 @@ static error_t parse_keyfile(char *fname, char **table) err_einval: fprintf(stderr, "Invalid parameter on line %d of %s\n", - line + 1, fname); + line, fname); return EINVAL; } @@ -312,6 +313,8 @@ static error_t parse_cfgfile(char *fname) while (fgets(s, sizeof(s), fin)) { char *p = s; + + line++; while (*p == ' ' || *p == '\t') p++; @@ -349,7 +352,6 @@ static error_t parse_cfgfile(char *fname) return ENOMEM; } nextcfg = nextcfg->next; - line++; } fclose(fin); @@ -357,7 +359,7 @@ static error_t parse_cfgfile(char *fname) err_einval: fprintf(stderr, "Invalid parameter on line %d of %s\n", - line + 1, fname); + line, fname); return EINVAL; } -- 2.7.4