diff options
author | Stef Walter <stefw@gnome.org> | 2013-02-06 14:54:53 +0100 |
---|---|---|
committer | Stef Walter <stefw@gnome.org> | 2013-02-06 14:54:53 +0100 |
commit | 2e8ce8c5ecb6d1f1c8f0af244d9f9b75dc6050ea (patch) | |
tree | d2845092b66331b9bdc54dd619bb6291fb4cea75 | |
parent | 0c6517104d1306228c31e596b0df6a4fb5af4dd1 (diff) |
Fix various clang analyzer warnings
* Add annotations to our precondition functions so that they
don't make the analyzer complain
-rw-r--r-- | common/compat.h | 13 | ||||
-rw-r--r-- | common/debug.h | 3 | ||||
-rw-r--r-- | p11-kit/conf.c | 2 | ||||
-rw-r--r-- | p11-kit/pin.c | 3 | ||||
-rw-r--r-- | p11-kit/uri.c | 1 | ||||
-rw-r--r-- | tools/extract-openssl.c | 9 | ||||
-rw-r--r-- | tools/extract.c | 3 | ||||
-rw-r--r-- | tools/tool.c | 3 |
8 files changed, 29 insertions, 8 deletions
diff --git a/common/compat.h b/common/compat.h index 7f848d2..5bcdfe2 100644 --- a/common/compat.h +++ b/common/compat.h @@ -51,6 +51,19 @@ #define GNUC_NULL_TERMINATED #endif +/* For detecting clang features */ +#ifndef __has_feature +#define __has_feature(x) 0 +#endif + +#ifndef CLANG_ANALYZER_NORETURN +#if __has_feature(attribute_analyzer_noreturn) +#define CLANG_ANALYZER_NORETURN __attribute__((analyzer_noreturn)) +#else +#define CLANG_ANALYZER_NORETURN +#endif +#endif + #ifndef HAVE_GETPROGNAME const char * getprogname (void); #endif diff --git a/common/debug.h b/common/debug.h index ff2af0f..eb2afa9 100644 --- a/common/debug.h +++ b/common/debug.h @@ -55,7 +55,8 @@ void p11_debug_message (int flag, ...) GNUC_PRINTF (2, 3); void p11_debug_precond (const char *format, - ...) GNUC_PRINTF (1, 2); + ...) GNUC_PRINTF (1, 2) + CLANG_ANALYZER_NORETURN; #define assert_not_reached() \ (assert (false && "this code should not be reached")) diff --git a/p11-kit/conf.c b/p11-kit/conf.c index 0f98636..28008aa 100644 --- a/p11-kit/conf.c +++ b/p11-kit/conf.c @@ -169,6 +169,7 @@ read_config_file (const char* filename, int flags) if (fread (config, 1, len, f) != len) { error = errno; p11_message ("couldn't read config file: %s", filename); + free (config); errno = error; return NULL; } @@ -559,7 +560,6 @@ load_configs_from_directory (const char *directory, path = strconcat (directory, "/", dp->d_name, NULL); return_val_if_fail (path != NULL, false); - is_dir = false; #ifdef HAVE_STRUCT_DIRENT_D_TYPE if(dp->d_type != DT_UNKNOWN) { is_dir = (dp->d_type == DT_DIR); diff --git a/p11-kit/pin.c b/p11-kit/pin.c index bb65e4c..afcb8ca 100644 --- a/p11-kit/pin.c +++ b/p11-kit/pin.c @@ -194,11 +194,13 @@ register_callback_unlocked (const char *pin_source, return_val_if_fail (callbacks != NULL, false); if (!p11_dict_set (gl.pin_sources, name, callbacks)) return_val_if_reached (false); + name = NULL; } if (!p11_array_push (callbacks, cb)) return_val_if_reached (false); + free (name); return true; } @@ -491,7 +493,6 @@ p11_kit_pin_file_callback (const char *pin_source, if (errno == EAGAIN) continue; error = errno; - error = errno; break; } else if (res == 0) { break; diff --git a/p11-kit/uri.c b/p11-kit/uri.c index 826c2c4..e8cb4c8 100644 --- a/p11-kit/uri.c +++ b/p11-kit/uri.c @@ -1236,7 +1236,6 @@ p11_kit_uri_parse (const char *string, P11KitUriType uri_type, return P11_KIT_URI_BAD_SCHEME; string = epos + 1; - ret = -1; /* Clear everything out */ memset (&uri->module, 0, sizeof (uri->module)); diff --git a/tools/extract-openssl.c b/tools/extract-openssl.c index fb87cd6..ae1bc27 100644 --- a/tools/extract-openssl.c +++ b/tools/extract-openssl.c @@ -613,6 +613,7 @@ p11_extract_openssl_directory (P11KitIter *iter, * conflicts with something we've already written out. */ + ret = true; linkname = symlink_for_subject_hash (ex); if (file && linkname) { ret = p11_save_symlink_in (dir, linkname, ".0", filename); @@ -620,12 +621,16 @@ p11_extract_openssl_directory (P11KitIter *iter, } linkname = symlink_for_subject_old_hash (ex); - if (file && linkname) { + if (ret && file && linkname) { ret = p11_save_symlink_in (dir, linkname, ".0", filename); free (linkname); } - ret = p11_save_write_and_finish (file, pem, length); + if (ret) + ret = p11_save_write_and_finish (file, pem, length); + else + p11_save_finish_file (file, false); + free (name); free (pem); } diff --git a/tools/extract.c b/tools/extract.c index abbb300..40a3911 100644 --- a/tools/extract.c +++ b/tools/extract.c @@ -238,6 +238,9 @@ limit_modules_if_necessary (CK_FUNCTION_LIST_PTR *modules, /* Count the number of modules */ for (out = 0; modules[out] != NULL; out++); + if (out == 0) + return; + order = malloc (sizeof (*order) * out); return_if_fail (order != NULL); diff --git a/tools/tool.c b/tools/tool.c index c825277..e971845 100644 --- a/tools/tool.c +++ b/tools/tool.c @@ -117,7 +117,7 @@ p11_tool_usage (const p11_tool_desc *usages, len = printf (" --%s", long_name); else len = printf (" -%c", (int)short_name); - if (longopt->has_arg) + if (longopt && longopt->has_arg) len += printf ("%s<%s>", long_name ? "=" : " ", usages[i].arg ? usages[i].arg : "..."); @@ -241,7 +241,6 @@ main (int argc, char *argv[]) */ for (in = 1, out = 1; in < argc; in++, out++) { - skip = false; /* Already seen the command, keep the arguments */ if (command) { |