Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Quiet compiler warnings for registry.exe #1858

Open
wants to merge 19 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
0ab3bb9
STY: First pass at eliminating compiler warnings.
DWesl Jan 20, 2023
9e252e5
STY: Create macro for extra space in destination buffer.
DWesl Oct 21, 2023
334a1a2
BLD,BUG: Don't add warning flags to default compilation
DWesl May 8, 2023
afd1c1a
BUG: io.h only available on Windows/Cygwin
DWesl May 9, 2023
173864f
STY: Add sufficient space to more destination buffers.
DWesl Oct 22, 2023
ba2eb1c
ENH: Include the nChmOpts check in the loop condition in gen_irr_diag.c
DWesl Oct 27, 2023
22c4ba0
STY: Delete the partial posix_spawn calls.
DWesl Oct 27, 2023
1208434
STY: Remove the partial memory leak fix.
DWesl Oct 27, 2023
317d219
BUG: Declare gen_packs and gen_packs_halo return types as int
DWesl Jan 8, 2024
8bdb29d
STY: Replace more integer literals with named constants.
DWesl Jan 25, 2024
d51f4ca
STY: Use TABLE_ENTRY for the max length of the KPP names
DWesl Jan 25, 2024
c116e16
STY: Pass number of characters in KPP name as printf argument
DWesl Jan 26, 2024
4ba1aab
STY: Two more file-path variables using NAMELEN.
DWesl Feb 8, 2024
764c90d
STY: combine fprintf calls, replace sprintf with strcpy.
DWesl Feb 8, 2024
894373e
STY: Keep nChmOpts an int
DWesl Feb 19, 2024
75742b9
Merge remote-tracking branch 'wrf-model/develop' into quiet-compiler-…
DWesl Feb 29, 2024
77fbd16
STY: Ensure line has enough space for all table entries.
DWesl Feb 29, 2024
6dc8eb0
STY: Revert narrowing of nChmOpts.
DWesl Feb 29, 2024
6c12eee
Merge changes from GitHub into local changes.
DWesl Feb 29, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion inc/streams.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
#ifndef MAX_HISTORY
# define MAX_HISTORY 12
# include <stdint.h>
# define MAX_HISTORY (UINT8_C(12))
# if (MAX_HISTORY > 120)
# warning If changing MAX_HISTORY to be above 120, check uses, loop variables,
# warning and destination string buffers to ensure the types used are wide
# warning enough. Enabling compiler warnings for format strings should help.
# endif
#endif
#ifndef IWORDSIZE
# define IWORDSIZE 4
Expand Down
37 changes: 19 additions & 18 deletions tools/Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
.SUFFIXES: .c .o

CC_TOOLS = cc
CC_TOOLS = $(CC)
CFLAGS = $(CC_TOOLS_CFLAGS) #-ansi
LDFLAGS =
DEBUG = -O0 -g
Expand Down Expand Up @@ -30,21 +30,22 @@ gen_comms.c : gen_comms.stub

# DO NOT DELETE THIS LINE -- make depend depends on it.

data.o: registry.h protos.h data.h
gen_allocs.o: protos.h registry.h data.h
gen_args.o: protos.h registry.h data.h
gen_scalar_derefs.o: protos.h registry.h data.h
gen_config.o: protos.h registry.h data.h
gen_defs.o: protos.h registry.h data.h
gen_mod_state_descr.o: protos.h registry.h data.h
gen_model_data_ord.o: protos.h registry.h data.h
gen_scalar_indices.o: protos.h registry.h data.h
gen_wrf_io.o: protos.h registry.h data.h
misc.o: protos.h registry.h data.h
my_strtok.o: registry.h protos.h data.h
reg_parse.o: registry.h protos.h data.h
registry.o: protos.h registry.h data.h
data.o: registry.h protos.h data.h ../inc/streams.h
gen_allocs.o: protos.h registry.h data.h ../inc/streams.h sym.h
gen_args.o: protos.h registry.h data.h ../inc/streams.h
gen_config.o: protos.h registry.h data.h ../inc/streams.h sym.h
gen_defs.o: protos.h registry.h data.h ../inc/streams.h
gen_interp.o: protos.h registry.h data.h ../inc/streams.h
gen_mod_state_descr.o: protos.h registry.h data.h ../inc/streams.h
gen_model_data_ord.o: protos.h registry.h data.h ../inc/streams.h
gen_scalar_derefs.o: protos.h registry.h data.h ../inc/streams.h
gen_scalar_indices.o: protos.h registry.h data.h ../inc/streams.h
gen_streams.o: protos.h registry.h data.h ../inc/streams.h sym.h
gen_wrf_io.o: protos.h registry.h data.h ../inc/streams.h sym.h
misc.o: protos.h registry.h data.h ../inc/streams.h
my_strtok.o: registry.h protos.h data.h ../inc/streams.h
reg_parse.o: registry.h protos.h data.h ../inc/streams.h sym.h
registry.o: protos.h registry.h data.h ../inc/streams.h sym.h
set_dim_strs.o: protos.h registry.h data.h ../inc/streams.h sym.h
sym.o: sym.h
type.o: registry.h protos.h data.h
gen_interp.o: registry.h protos.h data.h
gen_streams.o: registry.h protos.h data.h
type.o: registry.h protos.h data.h ../inc/streams.h
2 changes: 1 addition & 1 deletion tools/data.h
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ EXTERN node_t * Cycles ;

EXTERN node_t Domain ;

EXTERN char t1[NAMELEN], t2[NAMELEN], t3[NAMELEN], t4[NAMELEN], t5[NAMELEN], t6[NAMELEN] ;
EXTERN char t1[NAMELEN + EXTRA_FOR_DEST_BUFFER], t2[NAMELEN], t3[NAMELEN], t4[NAMELEN + EXTRA_FOR_DEST_BUFFER], t5[NAMELEN], t6[NAMELEN] ;
EXTERN char thiscom[4*NAMELEN] ;
EXTERN int model_order[3] ;

Expand Down
2 changes: 1 addition & 1 deletion tools/fseek_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ main()
FILE *fp ;
long long y ;
int retval ;
int result1 ;
int result1 = 0 ;
#ifdef TEST_FSEEKO
off_t x ;
off_t result2 ;
Expand Down
22 changes: 11 additions & 11 deletions tools/gen_allocs.c
Original file line number Diff line number Diff line change
Expand Up @@ -80,13 +80,13 @@ int
gen_alloc2 ( FILE * fp , char * structname , char * structname2 , node_t * node, int *j, int *iguy, int *fraction, int numguys, int frac, int sw ) /* 1 = allocate, 2 = just count */
{
node_t * p ;
int tag ;
char post[NAMELEN], post_for_count[NAMELEN] ;
char fname[NAMELEN], dname[NAMELEN], dname_tmp[NAMELEN] ;
char x[NAMELEN] ;
char x2[NAMELEN], fname2[NAMELEN] ;
char dimname[3][NAMELEN] ;
char tchar ;
int tag = 0 ;
char post[NAMELEN + 2 * EXTRA_FOR_DEST_BUFFER], post_for_count[NAMELEN + 2 * EXTRA_FOR_DEST_BUFFER] ;
char fname[NAMELEN], dname[NAMELEN + EXTRA_FOR_DEST_BUFFER], dname_tmp[NAMELEN] ;
char x[NAMELEN + EXTRA_FOR_DEST_BUFFER] ;
char x2[NAMELEN + EXTRA_FOR_DEST_BUFFER], fname2[2 * NAMELEN + EXTRA_FOR_DEST_BUFFER] ;
char dimname[3][NAMELEN + EXTRA_FOR_DEST_BUFFER] ;
char tchar = '\0';
unsigned int *io_mask ;
int nd ;
int restart ;
Expand Down Expand Up @@ -120,7 +120,7 @@ gen_alloc2 ( FILE * fp , char * structname , char * structname2 , node_t * node,
*/
if ( tag == 1 )
{
char dname_symbol[128] ;
char dname_symbol[NAMELEN + EXTRA_FOR_DEST_BUFFER] ;
sym_nodeptr sym_node ;

sprintf(dname_symbol, "DNAME_%s", dname_tmp ) ;
Expand Down Expand Up @@ -544,7 +544,7 @@ gen_ddt_write1 ( FILE * fp , char * structname , node_t * node )
{
node_t * p ;
int tag ;
char post[NAMELEN] ;
char post[NAMELEN + 2 * EXTRA_FOR_DEST_BUFFER] ;
char fname[NAMELEN] ;
char x[NAMELEN] ;

Expand Down Expand Up @@ -605,9 +605,9 @@ gen_dealloc2 ( FILE * fp , char * structname , node_t * node )
{
node_t * p ;
int tag ;
char post[NAMELEN] ;
char post[NAMELEN + 2 * EXTRA_FOR_DEST_BUFFER] ;
char fname[NAMELEN] ;
char x[NAMELEN] ;
char x[NAMELEN + EXTRA_FOR_DEST_BUFFER] ;

if ( node == NULL ) return(1) ;

Expand Down
2 changes: 1 addition & 1 deletion tools/gen_args.c
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ gen_args1 ( FILE * fp , char * outstr , char * structname ,
int tag ;
char post[NAMELEN] ;
char fname[NAMELEN] ;
char x[NAMELEN], y[NAMELEN] ;
char x[NAMELEN + EXTRA_FOR_DEST_BUFFER], y[NAMELEN] ;
char indices[NAMELEN] ;
int lenarg ;
int only4d = 0 ;
Expand Down
20 changes: 16 additions & 4 deletions tools/gen_config.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,16 @@ int
gen_namelist_defines ( char * dirname , int sw_dimension )
{
FILE * fp ;
char fname[NAMELEN] ;
char fname[NAMELEN + EXTRA_FOR_DEST_BUFFER] ;
char fn[NAMELEN] ;
node_t *p ;

sprintf( fn, "namelist_defines%s.inc", sw_dimension?"":"2" ) ;
if ( strlen(dirname) > 0 ) { sprintf(fname,"%s/%s",dirname,fn) ; }
if ( strlen(dirname) > 0 ) {
sprintf(fname,"%s/%s",dirname,fn) ;
} else {
sprintf(fname, "%s", fn) ;
}
if ((fp = fopen( fname , "w" )) == NULL ) return(1) ;
print_warning(fp,fname) ;

Expand Down Expand Up @@ -56,7 +60,11 @@ gen_namelist_defaults ( char * dirname )
char *fn = "namelist_defaults.inc" ;
node_t *p ;

if ( strlen(dirname) > 0 ) { sprintf(fname,"%s/%s",dirname,fn) ; }
if ( strlen(dirname) > 0 ) {
sprintf(fname,"%s/%s",dirname,fn) ;
} else {
sprintf(fname, "%s", fn) ;
}
if ((fp = fopen( fname , "w" )) == NULL ) return(1) ;
print_warning(fp,fname) ;

Expand Down Expand Up @@ -130,7 +138,11 @@ gen_namelist_script ( char * dirname )
char howset1[NAMELEN] ;
char howset2[NAMELEN] ;

if ( strlen(dirname) > 0 ) { sprintf(fname,"%s/%s",dirname,fn) ; }
if ( strlen(dirname) > 0 ) {
sprintf(fname,"%s/%s",dirname,fn) ;
} else {
sprintf(fname, "%s", fn) ;
}
if ((fp = fopen( fname , "w" )) == NULL ) return(1) ;

sym_forget() ;
Expand Down
6 changes: 3 additions & 3 deletions tools/gen_defs.c
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ int
gen_i1_decls ( char * dn )
{
FILE * fp ;
char fname[NAMELEN], post[NAMELEN] ;
char fname[NAMELEN+EXTRA_FOR_DEST_BUFFER], post[NAMELEN+EXTRA_FOR_DEST_BUFFER] ;
char * fn = "i1_decl.inc" ;
char * dimspec ;
node_t * p ;
Expand Down Expand Up @@ -139,8 +139,8 @@ gen_decls ( FILE * fp , node_t * node , int sw_ranges, int sw_point , int mask ,
{
node_t * p ;
int tag, ipass ;
char fname[NAMELEN], post[NAMELEN] ;
char * dimspec ;
char fname[NAMELEN], post[NAMELEN + 2 * EXTRA_FOR_DEST_BUFFER] ;
char * dimspec = "";
int bdyonly = 0 ;

if ( node == NULL ) return(1) ;
Expand Down
30 changes: 15 additions & 15 deletions tools/gen_interp.c
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ int contains_tok( char *s1, char *s2, char *delims )


/* Had to increase size for SOA from 4*4096 to 4*7000 */
char halo_define[4*7000], halo_use[NAMELEN], halo_id[NAMELEN], x[NAMELEN] ;
char halo_define[4*7000], halo_use[NAMELEN] = {'\0'}, halo_id[NAMELEN], x[2 * NAMELEN + EXTRA_FOR_DEST_BUFFER] ;

/*KAL added this for vertical interpolation */
/*DJW 131202 modified to create files required for vertical interpolation from parent to nest */
Expand Down Expand Up @@ -130,7 +130,7 @@ else if ( down_path[ipath] == FORCE_DOWN ) { sprintf(halo_id,"HALO_FORCE_DOWN")
else if ( down_path[ipath] == INTERP_UP ) { sprintf(halo_id,"HALO_INTERP_UP") ; }
else if ( down_path[ipath] == SMOOTH_UP ) { sprintf(halo_id,"HALO_INTERP_SMOOTH") ; }
sprintf(halo_define,"80:") ;
sprintf(halo_use,"") ;
halo_use[0] = '\0' ;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sprintf may be clearer, and the compiler may still notice the optimization.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or strcpy, since this isn't using any of the formatting features.

gen_nest_interp1 ( fp , Domain.fields, NULL, down_path[ipath], (down_path[ipath]==FORCE_DOWN)?2:2 ) ;
{
node_t * comm_struct ;
Expand Down Expand Up @@ -168,15 +168,15 @@ gen_nest_interp1 ( FILE * fp , node_t * node, char * fourdname, int down_path ,
char nddim2[3][2][NAMELEN] ;
char nmdim2[3][2][NAMELEN] ;
char npdim2[3][2][NAMELEN] ;
char vname[NAMELEN], vname2[NAMELEN] ;
char tag[NAMELEN], tag2[NAMELEN] ;
char vname[3 * NAMELEN + 5 * EXTRA_FOR_DEST_BUFFER], vname2[3 * NAMELEN + 5 * EXTRA_FOR_DEST_BUFFER] ;
char tag[NAMELEN] = {'\0'}, tag2[NAMELEN] = {'\0'} ;
char fcn_name[NAMELEN] ;
char xstag[NAMELEN], ystag[NAMELEN] ;
char dexes[NAMELEN] ;
char ndexes[NAMELEN] ;
char *maskstr ;
char *grid ;
char *colon, r[10],tx[80],temp[80],moredims[80] ;
char *colon, r[10],tx[2 * NAMELEN + EXTRA_FOR_DEST_BUFFER],temp[80],moredims[80] ;
int d ;
double real_store;
long long_store;
Expand All @@ -200,7 +200,7 @@ gen_nest_interp1 ( FILE * fp , node_t * node, char * fourdname, int down_path ,
if ( nest_mask & down_path )
{
if ( p->ntl > 1 ) { sprintf(tag,"_2") ; sprintf(tag2,"_%d", use_nest_time_level) ; }
else { sprintf(tag,"") ; sprintf(tag2,"") ; }
else { tag[0] = '\0'; tag2[0] = '\0'; }
Copy link
Contributor Author

@DWesl DWesl Jan 2, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sprintf or strcpy will likely be clearer, and the compiler might notice this optimization anyway.


/* construct variable name */
if ( p->node_kind & FOURD ) {
Expand Down Expand Up @@ -359,7 +359,7 @@ fprintf(fp," ngrid%%i_parent_start, ngrid%%j_parent_start,
fprintf(fp," ngrid%%parent_grid_ratio, ngrid%%parent_grid_ratio &\n") ;

{
char tmpstr[NAMELEN], *p1 ;
char tmpstr[2 * NAMELEN + EXTRA_FOR_DEST_BUFFER], *p1 ;
node_t * nd, * pp ;
pp = NULL ;
if ( p->node_kind & FOURD ) {
Expand All @@ -377,10 +377,10 @@ fprintf(fp," ngrid%%parent_grid_ratio, ngrid%%parent_grid_ratio
strcpy( tmpstr , pp->interpu_aux_fields ) ;
} else if ( down_path & FORCE_DOWN ) {
/* by default, add the boundary and boundary tendency fields to the arg list */
if ( (! p->node_kind) & FOURD ) {
sprintf( tmpstr , "%s_b,%s_bt,", pp->name, pp->name ) ;
if ( ! (p->node_kind & FOURD) ) {
snprintf( tmpstr , 2 * NAMELEN + EXTRA_FOR_DEST_BUFFER, "%s_b,%s_bt,", pp->name, pp->name ) ;
} else {
sprintf( tmpstr , "%s_b,%s_bt,", p->name, p->name ) ;
snprintf( tmpstr , 2 * NAMELEN + EXTRA_FOR_DEST_BUFFER, "%s_b,%s_bt,", p->name, p->name ) ;
}
strcat( tmpstr , pp->force_aux_fields ) ;
} else if ( down_path & INTERP_DOWN ) {
Expand Down Expand Up @@ -507,12 +507,12 @@ gen_nest_interp2 ( FILE * fp , node_t * node, char * fourdname, int down_path ,
char ddim[3][2][NAMELEN] ;
char mdim[3][2][NAMELEN] ;
char pdim[3][2][NAMELEN] ;
char vname[NAMELEN], vname2[NAMELEN] ;
char vname[3 * NAMELEN + 5 * EXTRA_FOR_DEST_BUFFER], vname2[3 * NAMELEN + 5 * EXTRA_FOR_DEST_BUFFER] ;
char tag[NAMELEN], tag2[NAMELEN] ;
char dexes[NAMELEN] ;
char ndexes[NAMELEN] ;
char *grid ;
char *colon,r[10],tx[80],temp[80],moredims[80] ;
char *colon,r[10],tx[2 * NAMELEN + EXTRA_FOR_DEST_BUFFER],temp[80],moredims[80] ;
int d ;
char zstag[NAMELEN];
char fcn_name[NAMELEN];
Expand Down Expand Up @@ -546,11 +546,11 @@ gen_nest_interp2 ( FILE * fp , node_t * node, char * fourdname, int down_path ,
set_dim_strs2 ( p , ddim , mdim , pdim , "", 1 ) ;
}
if ( !strcmp ( ddim[0][1], "kde") ||
!strcmp ( ddim[1][1], "kde") ||
!strcmp ( ddim[2][1], "kde")) {
!strcmp ( ddim[1][1], "kde") ||
!strcmp ( ddim[2][1], "kde")) {

if ( p->ntl > 1 ) { sprintf(tag,"_2") ; sprintf(tag2,"_%d", use_nest_time_level) ; }
else { sprintf(tag,"") ; sprintf(tag2,"") ; }
else { tag[0] = '\0'; tag2[0] = '\0'; }
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sprintf will likely be clearer, and the compiler may notice this optimization anyway.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alternately, strcpy/strncpy


/* construct variable name */
if ( p->node_kind & FOURD ) {
Expand Down
Loading