diff --git a/ncgen/main.c b/ncgen/main.c index f59e0d42f..96745f170 100644 --- a/ncgen/main.c +++ b/ncgen/main.c @@ -178,7 +178,7 @@ main( #ifdef __hpux setlocale(LC_CTYPE,""); #endif - + init_netcdf(); opterr = 1; /* print error message if bad option */ @@ -209,7 +209,7 @@ main( while ((c = getopt(argc, argv, "hbcfk:l:no:v:xdM:D:B:P")) != EOF) switch(c) { case 'd': - debug = 1; + debug = 1; break; case 'D': debug = atoi(optarg); @@ -238,29 +238,34 @@ main( l_flag = L_BINARY; break; case 'h': - header_only = 1; + header_only = 1; break; - case 'l': /* specify language, instead of using -c or -f or -b */ + case 'l': /* specify language, instead of using -c or -f or -b */ - { + { if(l_flag != 0) { - fprintf(stderr,"Please specify only one language\n"); - return 1; + fprintf(stderr,"Please specify only one language\n"); + return 1; } - lang_name = (char*) emalloc(strlen(optarg)+1); + if(!optarg) { + derror("%s: output language is null", + progname); + return(1); + } + lang_name = (char*) emalloc(strlen(optarg)+1); (void)strcpy(lang_name, optarg); for(langs=legallanguages;langs->name != NULL;langs++) { - if(strcmp(lang_name,langs->name)==0) { + if(strcmp(lang_name,langs->name)==0) { l_flag = langs->flag; - break; - } + break; + } } if(langs->name == NULL) { - derror("%s: output language %s not implemented", - progname, lang_name); - return(1); + derror("%s: output language %s not implemented", + progname, lang_name); + return(1); } - } + } break; case 'n': /* old version of -b, uses ".cdf" extension */ if(l_flag != 0) { @@ -278,7 +283,7 @@ main( break; case 'v': /* a deprecated alias for "kind" option */ /*FALLTHRU*/ - case 'k': /* for specifying variant of netCDF format to be generated + case 'k': /* for specifying variant of netCDF format to be generated Possible values are: 1 (=> classic 32 bit) 2 (=> classic 64 bit) @@ -415,7 +420,7 @@ main( cdlname = (char*)emalloc(NC_MAX_NAME); cdlname = nulldup(argv[0]); if(cdlname != NULL) { - if(strlen(cdlname) > NC_MAX_NAME) + if(strlen(cdlname) > NC_MAX_NAME) cdlname[NC_MAX_NAME] = '\0'; } } @@ -481,7 +486,7 @@ main( cmode_modifier |= (NC_DISKLESS|NC_NOCLOBBER); processsemantics(); - if(!syntax_only && error_count == 0) + if(!syntax_only && error_count == 0) define_netcdf(); return 0;