Makefile: Adding -Wshadow to prevent accident shadowing

Make sure we are not accidently using the incorrect variable
by not allowing 2 variables with the same name.

Signed-off-by: Otavio Pontes <otavio.pontes@intel.com>
This commit is contained in:
Otavio Pontes
2020-05-06 13:30:38 -07:00
parent 3870dc5181
commit 4e2e81fa4d
9 changed files with 52 additions and 53 deletions
+1
View File
@@ -12,6 +12,7 @@ AM_CFLAGS = -fPIE -fPIC -g -fno-common -std=gnu99 \
-Wunreachable-code \
-Wswitch-default \
-Wcast-align \
-Wshadow \
-Wbad-function-cast \
-Winline \
-Wundef \
+3 -3
View File
@@ -30,7 +30,7 @@
static bool cmdline_option_dependencies = false;
static bool cmdline_option_files = false;
static int cmdline_option_version = 0;
static char *bundle;
static char *param_bundle;
void bundle_info_set_option_version(int opt)
{
@@ -121,7 +121,7 @@ static bool parse_options(int argc, char **argv)
return false;
}
bundle = *(argv + optind);
param_bundle = *(argv + optind);
return true;
}
@@ -489,7 +489,7 @@ enum swupd_code bundle_info_main(int argc, char **argv)
progress_init_steps("bundle-info", steps_in_bundleinfo);
ret = bundle_info(bundle);
ret = bundle_info(param_bundle);
swupd_deinit();
progress_finish_steps(ret);
+4 -4
View File
@@ -35,7 +35,7 @@
#define VERIFY_PICKY 1
static char **bundles;
static char **param_bundles;
static bool cmdline_option_force = false;
static bool cmdline_option_recursive = false;
@@ -103,7 +103,7 @@ static bool parse_options(int argc, char **argv)
return false;
}
bundles = argv + ind;
param_bundles = argv + ind;
return true;
}
@@ -485,8 +485,8 @@ enum swupd_code bundle_remove_main(int argc, char **argv)
/* move the bundles provided in the command line into a
* list so it is easier to handle them */
for (; *bundles; ++bundles) {
char *bundle = *bundles;
for (; *param_bundles; ++param_bundles) {
char *bundle = *param_bundles;
bundles_list = list_append_data(bundles_list, bundle);
}
bundles_list = list_head(bundles_list);
+31 -31
View File
@@ -49,7 +49,7 @@
#define SWUPD_CURL_CONNECT_TIMEOUT 30
#define SWUPD_CURL_RCV_TIMEOUT 120
static CURL *curl = NULL;
static CURL *curl_main = NULL;
uint64_t total_curl_sz = 0;
@@ -124,7 +124,7 @@ exit:
return curl_ret;
}
static int check_connection_capath(const char *test_capath, const char *url)
static int check_connection_capath(CURL *curl, const char *test_capath, const char *url)
{
CURLcode curl_ret;
long response = 0;
@@ -186,11 +186,11 @@ static int check_connection_capath(const char *test_capath, const char *url)
int check_connection(char *url)
{
if (!curl) {
if (!curl_main) {
return swupd_curl_init(url) ? 0 : -1;
}
return check_connection_capath(NULL, url);
return check_connection_capath(curl_main, NULL, url);
}
static bool perform_curl_init(const char *url)
@@ -209,14 +209,14 @@ static bool perform_curl_init(const char *url)
return false;
}
curl = curl_easy_init();
if (curl == NULL) {
curl_main = curl_easy_init();
if (curl_main == NULL) {
error("Curl - Failed to initialize session\n");
curl_global_cleanup();
return false;
}
ret = check_connection_capath(NULL, url);
ret = check_connection_capath(curl_main, NULL, url);
if (ret == 0) {
return true;
} else if (ret == -CURLE_OPERATION_TIMEDOUT) {
@@ -236,7 +236,7 @@ static bool perform_curl_init(const char *url)
}
debug("Curl - Trying fallback CA path %s\n", tok);
ret = check_connection_capath(tok, url);
ret = check_connection_capath(curl_main, tok, url);
if (ret == 0) {
capath = strdup_or_die(tok);
break;
@@ -266,7 +266,7 @@ bool swupd_curl_init(const char *url)
static bool initialized = false;
if (initialized) {
return curl != NULL;
return curl_main != NULL;
}
initialized = true;
@@ -275,12 +275,12 @@ bool swupd_curl_init(const char *url)
void swupd_curl_cleanup(void)
{
if (!curl) {
if (!curl_main) {
return;
}
curl_easy_cleanup(curl);
curl = NULL;
curl_easy_cleanup(curl_main);
curl_main = NULL;
FREE(capath);
curl_global_cleanup();
}
@@ -301,35 +301,35 @@ double swupd_curl_query_content_size(char *url)
return -1;
}
curl_easy_reset(curl);
curl_easy_reset(curl_main);
curl_ret = swupd_curl_set_basic_options(curl, url, true);
curl_ret = swupd_curl_set_basic_options(curl_main, url, true);
if (curl_ret != CURLE_OK) {
return -1;
}
/* Set buffer for error string */
curl_ret = curl_easy_setopt(curl, CURLOPT_NOBODY, 1L);
curl_ret = curl_easy_setopt(curl_main, CURLOPT_NOBODY, 1L);
if (curl_ret != CURLE_OK) {
return -1;
}
curl_ret = curl_easy_setopt(curl, CURLOPT_HEADERFUNCTION, dummy_write_cb);
curl_ret = curl_easy_setopt(curl_main, CURLOPT_HEADERFUNCTION, dummy_write_cb);
if (curl_ret != CURLE_OK) {
return -1;
}
curl_ret = curl_easy_setopt(curl, CURLOPT_HEADER, 0L);
curl_ret = curl_easy_setopt(curl_main, CURLOPT_HEADER, 0L);
if (curl_ret != CURLE_OK) {
return -1;
}
curl_ret = curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, dummy_write_cb);
curl_ret = curl_easy_setopt(curl_main, CURLOPT_WRITEFUNCTION, dummy_write_cb);
if (curl_ret != CURLE_OK) {
return -1;
}
curl_ret = curl_easy_perform(curl);
curl_ret = curl_easy_perform(curl_main);
if (curl_ret != CURLE_OK) {
return -1;
}
@@ -339,7 +339,7 @@ double swupd_curl_query_content_size(char *url)
* NGINX which is the default content server used by clear). So if the file is
* not found we need to return a size of 0 instead, otherwise the download size
* calculation will be wrong */
curl_ret = curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &response);
curl_ret = curl_easy_getinfo(curl_main, CURLINFO_RESPONSE_CODE, &response);
if (curl_ret != CURLE_OK) {
return -1;
}
@@ -353,7 +353,7 @@ double swupd_curl_query_content_size(char *url)
return -1;
}
curl_ret = curl_easy_getinfo(curl, CURLINFO_CONTENT_LENGTH_DOWNLOAD, &content_size);
curl_ret = curl_easy_getinfo(curl_main, CURLINFO_CONTENT_LENGTH_DOWNLOAD, &content_size);
if (curl_ret != CURLE_OK) {
return -1;
}
@@ -521,7 +521,7 @@ static enum download_status swupd_curl_get_file_full(const char *url, char *file
void *local_ptr = &local;
restart_download:
curl_easy_reset(curl);
curl_easy_reset(curl_main);
if (!in_memory_file) {
// normal file download
@@ -531,7 +531,7 @@ restart_download:
if (resume_ok && resume_download_supported && lstat(filename, &stat) == 0) {
info("Curl - Resuming download for '%s'\n", url);
curl_ret = curl_easy_setopt(curl, CURLOPT_RESUME_FROM_LARGE, (curl_off_t)stat.st_size);
curl_ret = curl_easy_setopt(curl_main, CURLOPT_RESUME_FROM_LARGE, (curl_off_t)stat.st_size);
if (curl_ret != CURLE_OK) {
goto exit;
}
@@ -544,43 +544,43 @@ restart_download:
goto exit;
}
curl_ret = curl_easy_setopt(curl, CURLOPT_PRIVATE, (void *)local_ptr);
curl_ret = curl_easy_setopt(curl_main, CURLOPT_PRIVATE, (void *)local_ptr);
if (curl_ret != CURLE_OK) {
goto exit;
}
curl_ret = curl_easy_setopt(curl, CURLOPT_WRITEDATA, (void *)local.fh);
curl_ret = curl_easy_setopt(curl_main, CURLOPT_WRITEDATA, (void *)local.fh);
if (curl_ret != CURLE_OK) {
goto exit;
}
} else {
curl_ret = curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, swupd_download_file_to_memory);
curl_ret = curl_easy_setopt(curl_main, CURLOPT_WRITEFUNCTION, swupd_download_file_to_memory);
if (curl_ret != CURLE_OK) {
goto exit;
}
curl_ret = curl_easy_setopt(curl, CURLOPT_WRITEDATA, (void *)in_memory_file);
curl_ret = curl_easy_setopt(curl_main, CURLOPT_WRITEDATA, (void *)in_memory_file);
if (curl_ret != CURLE_OK) {
goto exit;
}
curl_ret = curl_easy_setopt(curl, CURLOPT_COOKIE, "request=uncached");
curl_ret = curl_easy_setopt(curl_main, CURLOPT_COOKIE, "request=uncached");
if (curl_ret != CURLE_OK) {
goto exit;
}
}
curl_ret = swupd_curl_set_basic_options(curl, url, true);
curl_ret = swupd_curl_set_basic_options(curl_main, url, true);
if (curl_ret != CURLE_OK) {
goto exit;
}
debug("Curl - Start sync download: %s -> %s\n", url, in_memory_file ? "<memory>" : filename);
curl_ret = curl_easy_perform(curl);
curl_ret = curl_easy_perform(curl_main);
exit:
if (!in_memory_file) {
curl_ret = swupd_download_file_close(curl_ret, &local);
}
status = process_curl_error_codes(curl_ret, curl);
status = process_curl_error_codes(curl_ret, curl_main);
debug("Curl - Complete sync download: %s -> %s, status=%d\n", url, in_memory_file ? "<memory>" : filename, status);
if (status == DOWNLOAD_STATUS_RANGE_ERROR) {
// Reset variable
+1 -1
View File
@@ -617,7 +617,7 @@ int swupd_curl_parallel_download_end(struct swupd_curl_parallel_handle *h, int *
//Retry failed downloads
for (l = h->failed; l;) {
struct multi_curl_file *file = l->data;
file = l->data;
if (file->retries < globals.max_retries &&
file->status != DOWNLOAD_STATUS_WRITE_ERROR) {
+2 -2
View File
@@ -30,7 +30,7 @@
#define PERCENTAGE_OFF -2
#define PERCENTAGE_ON -3
static void default_progress_function(const char *step_description, int current_step, int total_steps, int percentage);
static void default_progress_function(const char *step_description, int local_current_step, int local_total_steps, int percentage);
static const char *title = NULL;
static int total_steps = 0;
@@ -93,7 +93,7 @@ static void progress_spinner_start(void)
swupd_curl_download_set_progress_callback(progress_spinner_callback, &spinner_data);
}
static void default_progress_function(const char UNUSED_PARAM *step_description, int UNUSED_PARAM current_step, int UNUSED_PARAM total_steps, int percentage)
static void default_progress_function(const char UNUSED_PARAM *step_description, int UNUSED_PARAM local_current_step, int UNUSED_PARAM local_total_steps, int percentage)
{
if (percentage != PERCENTAGE_UNDEFINED &&
(percentage < 0 || percentage > 100)) {
+4 -4
View File
@@ -50,12 +50,12 @@ static X509 *get_cert_from_path(const char *certificate_path);
static X509_STORE *store = NULL;
static STACK_OF(X509) *x509_stack = NULL;
static int verify_callback_ignore_expiration(int ok, X509_STORE_CTX *store)
static int verify_callback_ignore_expiration(int ok, X509_STORE_CTX *local_store)
{
int error;
if (!ok) {
error = X509_STORE_CTX_get_error(store);
error = X509_STORE_CTX_get_error(local_store);
debug("Certificate verification error - %s\n",
X509_verify_cert_error_string(error));
if (error == X509_V_ERR_CERT_HAS_EXPIRED) {
@@ -67,12 +67,12 @@ static int verify_callback_ignore_expiration(int ok, X509_STORE_CTX *store)
return ok;
}
static int verify_callback(int ok, X509_STORE_CTX *store)
static int verify_callback(int ok, X509_STORE_CTX *local_store)
{
int error;
if (!ok) {
error = X509_STORE_CTX_get_error(store);
error = X509_STORE_CTX_get_error(local_store);
debug("Certificate verification error - %s\n",
X509_verify_cert_error_string(error));
}
-2
View File
@@ -30,8 +30,6 @@
#include "swupd.h"
struct list *subs;
static void free_subscription_data(void *data)
{
struct sub *sub = (struct sub *)data;
+6 -6
View File
@@ -141,7 +141,7 @@ int add_included_manifests(struct manifest *mom, struct list **subs)
return 0;
}
static enum swupd_code check_versions(int *current_version, int *server_version, int requested_version, char *path_prefix)
static enum swupd_code check_versions(int *current_version, int *server_version, int req_version, char *path_prefix)
{
int ret;
@@ -153,14 +153,14 @@ static enum swupd_code check_versions(int *current_version, int *server_version,
error("Update from version 0 not supported yet\n");
return SWUPD_INVALID_OPTION;
}
if (requested_version != -1) {
if (requested_version < *current_version) {
if (req_version != -1) {
if (req_version < *current_version) {
error("Requested version for update (%d) must be greater than current version (%d)\n",
requested_version, *current_version);
req_version, *current_version);
return SWUPD_INVALID_OPTION;
}
if (requested_version < *server_version) {
*server_version = requested_version;
if (req_version < *server_version) {
*server_version = req_version;
}
}