]> git.ozlabs.org Git - petitboot/commitdiff
discover: Fix bad check of version string
authorJoel Stanley <joel@jms.id.au>
Tue, 6 Mar 2018 04:02:16 +0000 (14:32 +1030)
committerSamuel Mendoza-Jonas <sam@mendozajonas.com>
Wed, 7 Mar 2018 05:24:31 +0000 (16:24 +1100)
Clang says this:

discover/device-handler.c:1564:27: warning: size argument in 'strncmp' call is a comparison [-Wmemsize-comparison]
                                        strlen(opt->version) == 0)) {
                                        ~~~~~~~~~~~~~~~~~~~~~^~~~
discover/device-handler.c:1563:5: note: did you mean to compare the result of 'strncmp' instead?
                                strncmp(opt->version, tmp->version,
                                ^

It looks like it's correct. However, we can go one better and drop the
pointless strncmp(foo, bar, strlen(bar)), as this is equivalent to
strcmp(foo, bar).

Signed-off-by: Joel Stanley <joel@jms.id.au>
Reviewed-by: Cyril Bur <cyrilbur@gmail.com>
Signed-off-by: Samuel Mendoza-Jonas <sam@mendozajonas.com>
discover/device-handler.c

index a6eb8843d514e0a99f9a53bb79ea951e8ec6f36a..569e65290bd7e98cef518b078a16f76547ecb564 100644 (file)
@@ -1560,8 +1560,7 @@ void device_handler_add_plugin_option(struct device_handler *handler,
                tmp = handler->plugins[i];
                /* If both id and version match, ignore */
                if (strncmp(opt->id, tmp->id, strlen(opt->id)) == 0 &&
-                               strncmp(opt->version, tmp->version,
-                                       strlen(opt->version) == 0)) {
+                               strcmp(opt->version, tmp->version) == 0) {
                        pb_log("discover: Plugin '%s' already exists, ignoring\n",
                                        opt->id);
                        return;