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

libdpkg: Remove unneeded and wrong caching of namevalue length member

All current namevalue arrays have the length member precomputed. And
the code was sneakily casting from const to non-const through a memcpy
to be able to do the cache.
Guillem Jover лет назад: 18
Родитель
Сommit
3b0e30015c
2 измененных файлов с 11 добавлено и 9 удалено
  1. 7 0
      ChangeLog
  2. 4 9
      lib/fields.c

+ 7 - 0
ChangeLog

@@ -1,3 +1,10 @@
+2008-07-02  Guillem Jover  <guillem@debian.org>
+
+	* lib/fields.c (convert_string): Change nvip to be const and use a
+	proper assignment instead of a sneaky cast through memcpy. Remove
+	unneeded length caching as all current namevalue arrays have it
+	precomputed.
+
 2008-07-02  Guillem Jover  <guillem@debian.org>
 
 	* lib/fields.c (convert_string): Use a capped string length instead

+ 4 - 9
lib/fields.c

@@ -38,19 +38,14 @@ convert_string(const char *filename, int lno, const char *what, int otherwise,
                const char **endpp)
 {
   const char *ep;
-  int c, l = 0;
-  struct namevalue *nvip= NULL;
-  memcpy(&nvip,&ivip,sizeof(struct namevalue *));
+  int c;
+  const struct namevalue *nvip = ivip;
 
   ep= startp;
   if (!*ep)
     parse_error(filename, lno, pigp, _("%s is missing"), what);
   while (nvip->name) {
-    if ((l= nvip->length) == 0) {
-      l= strlen(nvip->name);
-      nvip->length= (const int)l;
-    }
-    if (strncasecmp(nvip->name,startp,l) || nvip->name[l])
+    if (strncasecmp(nvip->name, startp, nvip->length))
       nvip++;
     else
       break;
@@ -60,7 +55,7 @@ convert_string(const char *filename, int lno, const char *what, int otherwise,
     parse_error(filename, lno, pigp, _("`%.*s' is not allowed for %s"),
                 strnlen(startp, 50), startp, what);
   }
-  ep = startp + l;
+  ep = startp + nvip->length;
   c = *ep;
   while (isspace(c)) c= *++ep;
   if (c && !endpp)