Index: client/civclient.c =================================================================== RCS file: /home/freeciv/CVS/freeciv/client/civclient.c,v retrieving revision 1.116 diff -u -r1.116 civclient.c --- client/civclient.c 2002/02/21 08:28:34 1.116 +++ client/civclient.c 2002/02/23 17:12:03 @@ -144,9 +144,11 @@ sz_strlcpy(player_name, option); else if ((option = get_option("--meta",argv,&i,argc))) sz_strlcpy(metaserver, option); - else if ((option = get_option("--port",argv,&i,argc))) - server_port=atoi(option); - else if ((option = get_option("--server",argv,&i,argc))) + else if ((option = get_option("--port",argv,&i,argc))) { + if(sscanf(option, "%d", &server_port) != 1) { + exit(EXIT_FAILURE); + } + } else if ((option = get_option("--server",argv,&i,argc))) sz_strlcpy(server_host, option); else if (is_option("--autoconnect",argv[i])) auto_connect = TRUE; Index: client/clinet.c =================================================================== RCS file: /home/freeciv/CVS/freeciv/client/clinet.c,v retrieving revision 1.62 diff -u -r1.62 clinet.c --- client/clinet.c 2002/02/19 16:41:16 1.62 +++ client/clinet.c 2002/02/23 17:12:03 @@ -481,9 +481,8 @@ { char *s; if ((s = strchr(server,':'))) { - port = atoi(&s[1]); - if (!port) { - port = 80; + if (sscanf(&s[1], "%d", &port) != 1) { + port = 80; } s[0] = '\0'; ++s; Index: client/gui-gtk/connectdlg.c =================================================================== RCS file: /home/freeciv/CVS/freeciv/client/gui-gtk/connectdlg.c,v retrieving revision 1.34 diff -u -r1.34 connectdlg.c --- client/gui-gtk/connectdlg.c 2002/02/19 20:03:04 1.34 +++ client/gui-gtk/connectdlg.c 2002/02/23 17:12:04 @@ -56,7 +56,7 @@ sz_strlcpy(player_name, gtk_entry_get_text(GTK_ENTRY(iname))); sz_strlcpy(server_host, gtk_entry_get_text(GTK_ENTRY(ihost))); - server_port=atoi(gtk_entry_get_text(GTK_ENTRY(iport))); + sscanf(gtk_entry_get_text(GTK_ENTRY(iport)), "%d", &server_port); if(connect_to_server(player_name, server_host, server_port, errbuf, sizeof(errbuf))!=-1) { Index: client/gui-gtk/diplodlg.c =================================================================== RCS file: /home/freeciv/CVS/freeciv/client/gui-gtk/diplodlg.c,v retrieving revision 1.30 diff -u -r1.30 diplodlg.c --- client/gui-gtk/diplodlg.c 2002/02/11 10:37:49 1.30 +++ client/gui-gtk/diplodlg.c 2002/02/23 17:12:04 @@ -883,9 +883,9 @@ pdialog->treaty.plr0 : pdialog->treaty.plr1; dp=gtk_entry_get_text(GTK_ENTRY(w)); - amount=atoi(dp); - - if(amount>=0 && amount<=pgiver->economic.gold) { + + if (sscanf(dp, "%d", &amount) == 1 && amount >= 0 + && amount <= pgiver->economic.gold) { struct packet_diplomacy_info pa; pa.plrno0=pdialog->treaty.plr0->player_no; pa.plrno1=pdialog->treaty.plr1->player_no; Index: client/gui-gtk/gamedlgs.c =================================================================== RCS file: /home/freeciv/CVS/freeciv/client/gui-gtk/gamedlgs.c,v retrieving revision 1.21 diff -u -r1.21 gamedlgs.c --- client/gui-gtk/gamedlgs.c 2002/02/12 09:36:45 1.21 +++ client/gui-gtk/gamedlgs.c 2002/02/23 17:12:05 @@ -385,7 +385,7 @@ break; case COT_INT: dp = gtk_entry_get_text(GTK_ENTRY(o->p_gui_data)); - *(o->p_value) = atoi(dp); + sscanf(dp, "%d", o->p_value); break; } } Index: client/gui-win32/connectdlg.c =================================================================== RCS file: /home/freeciv/CVS/freeciv/client/gui-win32/connectdlg.c,v retrieving revision 1.3 diff -u -r1.3 connectdlg.c --- client/gui-win32/connectdlg.c 2002/02/07 08:37:18 1.3 +++ client/gui-win32/connectdlg.c 2002/02/23 17:12:05 @@ -74,7 +74,7 @@ Edit_GetText(GetDlgItem(tab_childs[0],ID_CONNECTDLG_NAME),player_name,512); Edit_GetText(GetDlgItem(tab_childs[0],ID_CONNECTDLG_HOST),server_host,512); Edit_GetText(GetDlgItem(tab_childs[0],ID_CONNECTDLG_PORT),portbuf,10); - server_port=atoi(portbuf); + sscanf(portbuf, "%d", &server_port); if (connect_to_server(player_name,server_host,server_port, errbuf,sizeof(errbuf))!=-1) { Index: client/gui-win32/diplodlg.c =================================================================== RCS file: /home/freeciv/CVS/freeciv/client/gui-win32/diplodlg.c,v retrieving revision 1.4 diff -u -r1.4 diplodlg.c --- client/gui-win32/diplodlg.c 2002/02/12 11:45:54 1.4 +++ client/gui-win32/diplodlg.c 2002/02/23 17:12:05 @@ -248,8 +248,9 @@ struct player *pgiver; SetWindowText(edit,""); pgiver=plr?pdialog->treaty.plr1:pdialog->treaty.plr0; - amount=atoi(buf); - if(amount>=0 && amount<=pgiver->economic.gold) { + + if (sscanf(buf, "%d", &amount) == 1 && amount >= 0 + && amount <= pgiver->economic.gold) { struct packet_diplomacy_info pa; pa.plrno0=pdialog->treaty.plr0->player_no; pa.plrno1=pdialog->treaty.plr1->player_no; Index: client/gui-win32/optiondlg.c =================================================================== RCS file: /home/freeciv/CVS/freeciv/client/gui-win32/optiondlg.c,v retrieving revision 1.3 diff -u -r1.3 optiondlg.c --- client/gui-win32/optiondlg.c 2001/11/16 15:53:43 1.3 +++ client/gui-win32/optiondlg.c 2002/02/23 17:12:06 @@ -51,7 +51,7 @@ break; case COT_INT: GetWindowText((HWND)(o->p_gui_data),dp,sizeof(dp)); - *(o->p_value)=atoi(dp); + sscanf(dp, "%d", o->p_value); break; } } Index: client/gui-xaw/diplodlg.c =================================================================== RCS file: /home/freeciv/CVS/freeciv/client/gui-xaw/diplodlg.c,v retrieving revision 1.26 diff -u -r1.26 diplodlg.c --- client/gui-xaw/diplodlg.c 2002/02/10 21:48:27 1.26 +++ client/gui-xaw/diplodlg.c 2002/02/23 17:12:06 @@ -979,9 +979,8 @@ pdialog->treaty.plr0 : pdialog->treaty.plr1; XtVaGetValues(w, XtNstring, &dp, NULL); - amount=atoi(dp); - - if(amount>=0 && amount<=pgiver->economic.gold) { + if (sscanf(dp, "%d", &amount) == 1 && amount >= 0 + && amount <= pgiver->economic.gold) { struct packet_diplomacy_info pa; pa.plrno0=pdialog->treaty.plr0->player_no; pa.plrno1=pdialog->treaty.plr1->player_no; Index: client/gui-xaw/optiondlg.c =================================================================== RCS file: /home/freeciv/CVS/freeciv/client/gui-xaw/optiondlg.c,v retrieving revision 1.14 diff -u -r1.14 optiondlg.c --- client/gui-xaw/optiondlg.c 2001/01/30 23:38:55 1.14 +++ client/gui-xaw/optiondlg.c 2002/02/23 17:12:06 @@ -205,7 +205,7 @@ break; case COT_INT: XtVaGetValues(o->p_gui_data, XtNstring, &dp, NULL); - *(o->p_value) = atoi(dp); + sscanf(dp, "%d", o->p_value); break; } } Index: common/log.c =================================================================== RCS file: /home/freeciv/CVS/freeciv/common/log.c,v retrieving revision 1.30 diff -u -r1.30 log.c --- common/log.c 2002/02/16 17:05:06 1.30 +++ common/log.c 2002/02/23 17:12:07 @@ -76,7 +76,10 @@ n++; } if (n == 0) { - level = atoi(level_str); + if (sscanf(level_str, "%d", &level) != 1) { + fprintf(stderr, _("Bad log level \"%s\".\n"), level_str); + return -1; + } if (level >= LOG_FATAL && level <= max_level) { return level; } else { @@ -129,8 +132,14 @@ c = strchr(c, ','); if (c && *pc != '\0' && c[1] != '\0') { c[0] = '\0'; - logd_files[i].min = atoi(pc); - logd_files[i].max = atoi(c+1); + if (sscanf(pc, "%d", &logd_files[i].min) != 1) { + fprintf(stderr, _("Not an integer: '%s'\n"), pc); + FRETURN(-1); + } + if (sscanf(c + 1, "%d", &logd_files[i].max) != 1) { + fprintf(stderr, _("Not an integer: '%s'\n"), c + 1); + FRETURN(-1); + } } } if(strlen(tok)==0) { Index: common/registry.c =================================================================== RCS file: /home/freeciv/CVS/freeciv/common/registry.c,v retrieving revision 1.44 diff -u -r1.44 registry.c --- common/registry.c 2002/02/16 17:05:08 1.44 +++ common/registry.c 2002/02/23 17:12:07 @@ -338,7 +338,9 @@ } } else { pentry->svalue = NULL; - pentry->ivalue = atoi(tok); + if (sscanf(tok, "%d", &pentry->ivalue) != 1) { + freelog(LOG_ERROR, "'%s' isn't an integer", tok); + } if (SECF_DEBUG_ENTRIES) { freelog(LOG_DEBUG, "entry %s %d", name, pentry->ivalue); } Index: server/civserver.c =================================================================== RCS file: /home/freeciv/CVS/freeciv/server/civserver.c,v retrieving revision 1.207 diff -u -r1.207 civserver.c --- server/civserver.c 2002/02/21 08:28:35 1.207 +++ server/civserver.c 2002/02/23 17:12:08 @@ -87,13 +87,19 @@ sz_strlcpy(srvarg.metaserver_addr, argv[inx]); meta_addr_split(); srvarg.metaserver_no_send = FALSE; /* --Metaserver implies --meta */ - } else if ((option = get_option("--port", argv, &inx, argc))) - srvarg.port = atoi(option); - else if ((option = get_option("--read", argv, &inx, argc))) + } else if ((option = get_option("--port", argv, &inx, argc))) { + if (sscanf(option, "%d", &srvarg.port) != 1) { + showhelp = TRUE; + break; + } + } else if ((option = get_option("--read", argv, &inx, argc))) srvarg.script_filename = option; - else if ((option = get_option("--quitidle", argv, &inx, argc))) - srvarg.quitidle = atoi(option); - else if ((option = get_option("--server", argv, &inx, argc))) + else if ((option = get_option("--quitidle", argv, &inx, argc))) { + if (sscanf(option, "%d", &srvarg.quitidle) != 1) { + showhelp = TRUE; + break; + } + } else if ((option = get_option("--server", argv, &inx, argc))) sz_strlcpy(srvarg.metaserver_servername, option); else if ((option = get_option("--debug", argv, &inx, argc))) { srvarg.loglevel = log_parse_level_str(option); @@ -254,10 +260,7 @@ GetIText( the_handle, (unsigned char *)srvarg.log_filename); GetDItem( optptr, 12, &the_type, &the_handle, &the_rect); GetIText( the_handle, the_string); - if (atoi((char*)the_string)>0) - { - srvarg.port=atoi((char*)the_string); - } + sscanf(the_string, "%d", srvarg.port); GetDItem( optptr, 10, &the_type, &the_handle, &the_rect); GetIText( the_handle, (unsigned char *)srvarg.script_filename); GetDItem(optptr, 15, &the_type, &the_handle, &the_rect); Index: server/meta.c =================================================================== RCS file: /home/freeciv/CVS/freeciv/server/meta.c,v retrieving revision 1.47 diff -u -r1.47 meta.c --- server/meta.c 2002/02/21 09:44:53 1.47 +++ server/meta.c 2002/02/23 17:12:08 @@ -103,14 +103,10 @@ *************************************************************************/ void meta_addr_split(void) { - char *metaserver_port_separator; - int specified_port; + char *metaserver_port_separator = strchr(srvarg.metaserver_addr,':'); - if ((metaserver_port_separator = strchr(srvarg.metaserver_addr,':'))) { - metaserver_port_separator[0] = '\0'; - if ((specified_port=atoi(&metaserver_port_separator[1]))) { - srvarg.metaserver_port = (unsigned short int)specified_port; - } + if (metaserver_port_separator) { + sscanf(metaserver_port_separator + 1, "%hd", &srvarg.metaserver_port); } } Index: server/stdinhand.c =================================================================== RCS file: /home/freeciv/CVS/freeciv/server/stdinhand.c,v retrieving revision 1.208 diff -u -r1.208 stdinhand.c --- server/stdinhand.c 2002/02/21 09:44:54 1.208 +++ server/stdinhand.c 2002/02/23 17:12:11 @@ -2712,9 +2712,8 @@ op = &settings[cmd]; - if (SETTING_IS_INT(op)) { - val = atoi(arg); - if (!val && arg[0] != '0') { + if (SETTING_IS_INT(op)) { + if (sscanf(arg, "%d", &val) != 1) { cmd_reply(CMD_SET, caller, C_SYNTAX, _("Value must be an integer.")); } else if (val >= op->min_value && val <= op->max_value) {