Clang compiler warnings and const correctness

This commit is contained in:
Shahram Najm 2019-08-12 16:00:15 +01:00
parent c3f10308de
commit 3e53285b9e
9 changed files with 94 additions and 100 deletions

View File

@ -647,12 +647,12 @@ const char* grib_get_type_name(int type)
{
switch(type)
{
case GRIB_TYPE_LONG: return "long"; break;
case GRIB_TYPE_STRING: return "string"; break;
case GRIB_TYPE_BYTES: return "bytes"; break;
case GRIB_TYPE_DOUBLE: return "double"; break;
case GRIB_TYPE_LABEL: return "label"; break;
case GRIB_TYPE_SECTION: return "section"; break;
case GRIB_TYPE_LONG: return "long";
case GRIB_TYPE_STRING: return "string";
case GRIB_TYPE_BYTES: return "bytes";
case GRIB_TYPE_DOUBLE: return "double";
case GRIB_TYPE_LABEL: return "label";
case GRIB_TYPE_SECTION: return "section";
}
return "unknown";
}
@ -756,14 +756,14 @@ int grib_accessor_has_attributes(grib_accessor* a)
return a->attributes[0] ? 1 : 0 ;
}
grib_accessor* grib_accessor_get_attribute(grib_accessor* a,const char* name)
grib_accessor* grib_accessor_get_attribute(grib_accessor* a, const char* name)
{
int index=0;
char* p=0;
const char* p=0;
char* basename=NULL;
char* attribute_name=NULL;
const char* attribute_name=NULL;
grib_accessor* acc=NULL;
p=(char*)name;
p=name;
while ( *(p+1) != '\0' && ( *p != '-' || *(p+1)!= '>' ) ) p++;
if (*(p+1) == '\0') {
return _grib_accessor_get_attribute(a,name,&index);

View File

@ -19,8 +19,8 @@ GRIB_INLINE static int grib_inline_strcmp(const char* a,const char* b)
GRIB_INLINE static int grib_inline_rstrcmp(const char* a,const char* b)
{
char* p=(char*)a;
char* q=(char*)b;
const char* p=a;
const char* q=b;
while (*p != 0) p++;
while (*q != 0) q++;
q--;p--;
@ -38,15 +38,14 @@ struct grib_error {
grib_error* next;
};
grib_error* error_summary;
compare_double_proc compare_double;
double global_tolerance=0;
int packingCompare=0;
grib_string_list* blacklist=0;
grib_string_list* keys_list = NULL; /* Used to determine rank of key */
int isLeafKey = 0; /* 0 if key is top-level, 1 if key has no children attributes */
int compareAbsolute=1;
static grib_error* error_summary;
static compare_double_proc compare_double;
static double global_tolerance=0;
static int packingCompare=0;
static grib_string_list* blacklist=0;
static grib_string_list* keys_list = NULL; /* Used to determine rank of key */
static int isLeafKey = 0; /* 0 if key is top-level, 1 if key has no children attributes */
static int compareAbsolute=1;
static int compare_handles(grib_handle* handle1, grib_handle* handle2, grib_runtime_options* options);
static int compare_values(grib_runtime_options* options, grib_handle* handle1, grib_handle *handle2, const char *name, int type);
@ -55,27 +54,27 @@ static int compare_attributes(grib_handle* handle1, grib_handle* handle2, grib_r
static int compare_attribute(grib_handle* handle1, grib_handle* handle2, grib_runtime_options* options,
grib_accessor* a, const char* prefix, int* err);
int error=0;
int count=0;
int lastPrint=0;
int force=0;
static int error=0;
static int count=0;
static int lastPrint=0;
static int force=0;
/* ECC-651: Boolean 'two_way' set to 1 when '-2' option used */
int two_way=0;
static int two_way=0;
/* Boolean 'handles_swapped' relevant in 'two_way' mode:
* 0 means: h1 is first file, h2 is second file
* 1 means: h1 is second file, h2 is first file
*/
int handles_swapped=0;
static int handles_swapped=0;
double maxAbsoluteError = 1e-19;
int onlyListed=1;
int headerMode=0;
int morein1=0;
int morein2=0;
int listFromCommandLine;
int verbose=0;
int tolerance_factor=1;
static double maxAbsoluteError = 1e-19;
static int onlyListed=1;
static int headerMode=0;
static int morein1=0;
static int morein2=0;
static int listFromCommandLine;
static int verbose=0;
static int tolerance_factor=1;
static int write_error=0;
/* Create the list of keys (global variable keys_list) */
@ -218,10 +217,10 @@ grib_option grib_options[]={
{"v",0,0,0,1,0}
};
grib_handle* global_handle=NULL;
int counter=0;
int start=-1;
int end=-1;
static grib_handle* global_handle=NULL;
static int counter=0;
static int start=-1;
static int end=-1;
const char* grib_tool_description=
"Compare BUFR messages contained in two files."
@ -628,8 +627,8 @@ static char* double_as_string(grib_context* c, double v)
/* Return the part of the key name without the '#rank#' part */
static char* get_keyname_without_rank(const char* name)
{
char* p=(char*)name;
char* pEnd=p;
const char* p=name;
char* pEnd;
char* ret=NULL;
if (*p=='#') {
@ -1122,7 +1121,6 @@ static int compare_values(grib_runtime_options* options, grib_handle* handle1, g
save_error(c,name);
printf("Cannot compare [%s], unsupported type %d\n",name,type1);
return GRIB_UNABLE_TO_COMPARE_ACCESSORS;
break;
}
return GRIB_SUCCESS;
@ -1292,7 +1290,7 @@ static int compare_handles(grib_handle* handle1, grib_handle* handle2, grib_runt
if ( listFromCommandLine && onlyListed ) {
for (i=0; i< options->compare_count; i++) {
if (blacklisted((char*)options->compare[i].name)) continue;
if (blacklisted(options->compare[i].name)) continue;
if (options->compare[i].type == GRIB_NAMESPACE) {
iter=grib_keys_iterator_new(handle1,0,options->compare[i].name);
if (!iter) {

View File

@ -42,7 +42,6 @@ const char* grib_tool_name="bufr_get";
const char* grib_tool_usage="[options] file file ...";
int grib_options_count=sizeof(grib_options)/sizeof(grib_option);
grib_nearest* n=NULL;
int main(int argc, char *argv[])
{

View File

@ -19,8 +19,8 @@ GRIB_INLINE static int grib_inline_strcmp(const char* a,const char* b)
GRIB_INLINE static int grib_inline_rstrcmp(const char* a,const char* b)
{
char* p=(char*)a;
char* q=(char*)b;
const char* p=a;
const char* q=b;
while (*p != 0) p++;
while (*q != 0) q++;
q--;p--;
@ -38,37 +38,36 @@ struct grib_error {
grib_error* next;
};
grib_error* error_summary;
compare_double_proc compare_double;
double global_tolerance=0;
int packingCompare=0;
grib_string_list* blacklist=0;
int compareAbsolute=1;
static grib_error* error_summary;
static compare_double_proc compare_double;
static double global_tolerance=0;
static int packingCompare=0;
static grib_string_list* blacklist=0;
static int compareAbsolute=1;
static int compare_handles(grib_handle* h1,grib_handle* h2,grib_runtime_options* options);
static int compare_values(grib_runtime_options* options,grib_handle* h1,grib_handle *h2,const char *name,int type);
int error=0;
int count=0;
int lastPrint=0;
int force=0;
static int error=0;
static int count=0;
static int lastPrint=0;
static int force=0;
/* ECC-651: Boolean 'two_way' set to 1 when '-2' option used */
int two_way=0;
static int two_way=0;
/* Boolean 'handles_swapped' relevant in 'two_way' mode:
* 0 means: h1 is first file, h2 is second file
* 1 means: h1 is second file, h2 is first file
*/
int handles_swapped=0;
static int handles_swapped=0;
double maxAbsoluteError = 1e-19;
int onlyListed=1;
int headerMode=0;
int morein1=0;
int morein2=0;
int listFromCommandLine;
int verbose=0;
double tolerance_factor=1;
static double maxAbsoluteError = 1e-19;
static int onlyListed=1;
static int headerMode=0;
static int morein1=0;
static int morein2=0;
static int listFromCommandLine;
static int verbose=0;
static double tolerance_factor=1;
/* Returns 0 when the values are considered the same */
static double compare_double_absolute(double *a,double *b,double tolerance)
@ -150,10 +149,10 @@ grib_option grib_options[]={
{"v",0,0,0,1,0}
};
grib_handle* global_handle=NULL;
int global_counter=0;
int theStart=-1;
int theEnd=-1;
static grib_handle* global_handle=NULL;
static int global_counter=0;
static int theStart=-1;
static int theEnd=-1;
const char* grib_tool_description=
"Compare GRIB messages contained in two files."
@ -1074,7 +1073,6 @@ static int compare_values(grib_runtime_options* options,grib_handle* h1,grib_han
save_error(c,name);
printf("Cannot compare [%s], unsupported type %d\n",name,type1);
return GRIB_UNABLE_TO_COMPARE_ACCESSORS;
break;
}
return GRIB_SUCCESS;

View File

@ -46,10 +46,10 @@ const char* grib_tool_name="grib_get";
const char* grib_tool_usage="[options] grib_file grib_file ...";
int grib_options_count=sizeof(grib_options)/sizeof(grib_option);
double lat=0;
double lon=0;
int mode=0;
grib_nearest* nearest=NULL;
static double lat=0;
static double lon=0;
static int mode=0;
static grib_nearest* nearest=NULL;
int main(int argc, char *argv[])
{

View File

@ -18,9 +18,9 @@
const char* grib_tool_description="Build an index file for a set of input GRIB files.";
const char* grib_tool_name="grib_index_build";
const char* grib_tool_usage="[options] grib_file grib_file ... ";
grib_index* idx=NULL;
char* keys;
char* default_keys = "mars";
static grib_index* idx=NULL;
static char* keys;
static char* default_keys = "mars";
grib_option grib_options[]={
/* {id, args, help}, on, command_line, value */
@ -39,7 +39,7 @@ grib_option grib_options[]={
}
};
int compress_index;
static int compress_index;
int grib_options_count=sizeof(grib_options)/sizeof(grib_option);

View File

@ -49,12 +49,11 @@ const char* grib_tool_usage="[options] grib_file grib_file ...";
static char* new_handle="";
int grib_options_count=sizeof(grib_options)/sizeof(grib_option);
double lat=0;
double lon=0;
int mode=0;
static double lat=0;
static double lon=0;
static int mode=0;
static int json_latlon=0;
grib_nearest* nearest=NULL;
static grib_nearest* nearest=NULL;
int main(int argc, char *argv[])
{

View File

@ -21,11 +21,11 @@ extern int optind;
#include "wingetopt.h"
#endif
const char* names[]={"parameter","vertical","geography","data","mars","local"};
int names_count=6;
static const char* names[]={"parameter","vertical","geography","data","mars","local"};
static int names_count=6;
/* id,args,help */
grib_options_help grib_options_help_list[] ={
static grib_options_help grib_options_help_list[] ={
{"a",0,"Dump aliases.\n"},
{"b:","key,key,...",
"\n\t\tAll the keys in this list are skipped in the comparison. Bit-by-bit compare on.\n"},
@ -111,7 +111,7 @@ grib_options_help grib_options_help_list[] ={
};
int grib_options_help_count=sizeof(grib_options_help_list)/sizeof(grib_options_help);
static int grib_options_help_count=sizeof(grib_options_help_list)/sizeof(grib_options_help);
void usage(void)

View File

@ -46,7 +46,7 @@ static int scan(grib_context* c,grib_runtime_options* options,const char* dir);
FILE* dump_file;
grib_runtime_options global_options={
static grib_runtime_options global_options={
0, /* verbose */
0, /* fail */
0, /* skip */
@ -196,7 +196,7 @@ static int grib_tool_with_orderby(grib_runtime_options* options)
grib_handle* h=NULL;
grib_tools_file* infile=options->infile;
char** filenames;
size_t files_count=0;
int files_count=0;
grib_fieldset* set=NULL;
int i=0;
grib_context* c=grib_context_get_default();
@ -270,7 +270,7 @@ static int grib_tool_with_orderby(grib_runtime_options* options)
return 0;
}
char iobuf[1024*1024];
static char iobuf[1024*1024];
static int grib_tool_without_orderby(grib_runtime_options* options)
{
@ -669,8 +669,8 @@ static void grib_tools_set_print_keys(grib_runtime_options* options, grib_handle
for (i=0;i<options->requested_print_keys_count;i++) {
options->print_keys[options->print_keys_count].name=options->requested_print_keys[i].name;
if (strlen(options->requested_print_keys[i].name)>options->default_print_width)
options->default_print_width=strlen(options->requested_print_keys[i].name);
if (strlen(options->requested_print_keys[i].name) > options->default_print_width)
options->default_print_width = (int)strlen(options->requested_print_keys[i].name);
options->print_keys[options->print_keys_count].type=options->requested_print_keys[i].type;
options->print_keys_count++;
}
@ -693,7 +693,7 @@ static void grib_tools_set_print_keys(grib_runtime_options* options, grib_handle
}
options->print_keys[options->print_keys_count].name=strdup(name);
if (strlen(name)>options->default_print_width)
options->default_print_width=strlen(name);
options->default_print_width=(int)strlen(name);
options->print_keys[options->print_keys_count].type=GRIB_TYPE_STRING;
options->print_keys_count++;
}
@ -701,14 +701,14 @@ static void grib_tools_set_print_keys(grib_runtime_options* options, grib_handle
grib_keys_iterator_delete(kiter);
if (options->print_keys_count==0 && options->latlon == 0 ) {
int j=0,k=0,ns_count=0;
char* all_namespace_vals[1024] = {NULL,}; /* sorted array containing all namespaces */
const char* all_namespace_vals[1024] = {NULL,}; /* sorted array containing all namespaces */
printf("ERROR: namespace \"%s\" does not contain any key.\n",ns);
printf("Here are the available namespaces in this message:\n");
for (i=0; i<ACCESSORS_ARRAY_SIZE; i++) {
grib_accessor* anAccessor = h->accessors[i];
if (anAccessor) {
for (j=0; j<MAX_ACCESSOR_NAMES; j++) {
char* a_namespace = (char*)anAccessor->all_name_spaces[j];
const char* a_namespace = anAccessor->all_name_spaces[j];
if (a_namespace) {
all_namespace_vals[k++] = a_namespace;
ns_count++;
@ -974,7 +974,7 @@ void grib_print_key_values(grib_runtime_options* options, grib_handle* h)
}
}
strlenvalue = strlen(value);
strlenvalue = (int)strlen(value);
width = strlenvalue < options->default_print_width ?
options->default_print_width + 2 :
@ -999,7 +999,7 @@ void grib_print_key_values(grib_runtime_options* options, grib_handle* h)
written_to_dump=1;
} else if (options->latlon_mode==1) {
sprintf(value,options->format,options->values[options->latlon_idx]);
strlenvalue = strlen(value);
strlenvalue = (int)strlen(value);
width = strlenvalue < options->default_print_width ?
options->default_print_width + 2 :
strlenvalue + 2;
@ -1035,7 +1035,7 @@ void grib_print_key_values(grib_runtime_options* options, grib_handle* h)
}
sprintf(value,options->format,v);
strlenvalue = strlen(value);
strlenvalue = (int)strlen(value);
width = strlenvalue < options->default_print_width ?
options->default_print_width + 2 :
strlenvalue + 2;