Просмотр исходного кода

libdpkg: Move field matching into for (;;) bodies in pkg_parse_field()

The current code is performing the field matching in the for (;;)
conditional, which implies and empty for (;;) body and needs inverted
logic to work. Move the matching into the body as that's the more
natural place for it to be and easier to read.
Guillem Jover лет назад: 15
Родитель
Сommit
5f2b4a4632
1 измененных файлов с 7 добавлено и 6 удалено
  1. 7 6
      lib/dpkg/parse.c

+ 7 - 6
lib/dpkg/parse.c

@@ -103,17 +103,18 @@ pkg_parse_field(struct parsedb_state *ps, struct field_state *fs,
   const struct fieldinfo *fip;
   int *ip;
 
-  for (nick = nicknames;
-       nick->nick && (strncasecmp(nick->nick, fs->fieldstart, fs->fieldlen) ||
-                      nick->nick[fs->fieldlen] != '\0'); nick++) ;
+  for (nick = nicknames; nick->nick; nick++)
+    if (strncasecmp(nick->nick, fs->fieldstart, fs->fieldlen) == 0 &&
+        nick->nick[fs->fieldlen] == '\0')
+      break;
   if (nick->nick) {
     fs->fieldstart = nick->canon;
     fs->fieldlen = strlen(fs->fieldstart);
   }
 
-  for (fip = fieldinfos, ip = fs->fieldencountered;
-       fip->name && strncasecmp(fs->fieldstart, fip->name, fs->fieldlen);
-       fip++, ip++) ;
+  for (fip = fieldinfos, ip = fs->fieldencountered; fip->name; fip++, ip++)
+    if (strncasecmp(fip->name, fs->fieldstart, fs->fieldlen) == 0)
+      break;
   if (fip->name) {
     if ((*ip)++)
       parse_error(ps, pkg,