chiark / gitweb /
udev: rules - print the first invalid character
authorTom Gundersen <teg@jklm.no>
Fri, 28 Nov 2014 20:46:34 +0000 (21:46 +0100)
committerTom Gundersen <teg@jklm.no>
Fri, 28 Nov 2014 20:54:24 +0000 (21:54 +0100)
The current code would print the character following the first invalid
character.

Given an udev rules-file without a trailing newline we would otherwise print
garbage:

  invalid key/value pair in file /usr/lib/udev/rules.d/40-usb-media-players.rules
  on line 26, starting at character 25 ('m')

This is now changed to print

  invalid key/value pair in file /usr/lib/udev/rules.d/40-usb-media-players.rules
  on line 26, starting at character 25 ('')

(still not very good as printing \0 just gives the empty string)

src/udev/udev-rules.c

index a261fbf9780fd843e99e0adbdc5375a9675d0fb0..131abd69f5b46905304a565d323e915d630c7a89 100644 (file)
@@ -1068,13 +1068,13 @@ static int add_rule(struct udev_rules *rules, char *line,
                         /* If we aren't at the end of the line, this is a parsing error.
                          * Make a best effort to describe where the problem is. */
                         if (*linepos != '\n') {
                         /* If we aren't at the end of the line, this is a parsing error.
                          * Make a best effort to describe where the problem is. */
                         if (*linepos != '\n') {
-                                char buf[2] = {linepos[1]};
+                                char buf[2] = {*linepos};
                                 _cleanup_free_ char *tmp;
 
                                 tmp = cescape(buf);
                                 log_error("invalid key/value pair in file %s on line %u, starting at character %tu ('%s')",
                                           filename, lineno, linepos - line + 1, tmp);
                                 _cleanup_free_ char *tmp;
 
                                 tmp = cescape(buf);
                                 log_error("invalid key/value pair in file %s on line %u, starting at character %tu ('%s')",
                                           filename, lineno, linepos - line + 1, tmp);
-                                if (linepos[1] == '#')
+                                if (*linepos == '#')
                                         log_error("hint: comments can only start at beginning of line");
                         }
                         break;
                                         log_error("hint: comments can only start at beginning of line");
                         }
                         break;