From 3b0e30015c9948f13fd835f985fddd4dcc73c598 Mon Sep 17 00:00:00 2001 From: Guillem Jover Date: Wed, 2 Jul 2008 08:45:09 +0300 Subject: [PATCH] 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. --- ChangeLog | 7 +++++++ lib/fields.c | 13 ++++--------- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/ChangeLog b/ChangeLog index 9021adc7..762dbe20 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2008-07-02 Guillem Jover + + * 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 * lib/fields.c (convert_string): Use a capped string length instead diff --git a/lib/fields.c b/lib/fields.c index 0ef20a84..7e1abf06 100644 --- a/lib/fields.c +++ b/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) -- 2.39.5