tPatch from Barry deFreese; remove deprecated code, and fix unsafe use of forma… | |
git clone git://src.adamsgaard.dk/vaccinewars | |
Log | |
Files | |
Refs | |
README | |
LICENSE | |
--- | |
commit 1edff0de84a71af1c637e1cfc1558eba47abc94a | |
parent d954538689ac49f9a3a254dfb42207529e54c8ac | |
Author: Ben Webb <[email protected]> | |
Date: Tue, 9 Jul 2013 05:55:00 +0000 | |
Patch from Barry deFreese; remove deprecated code, and fix unsafe | |
use of format strings. | |
Diffstat: | |
M src/curses_client/curses_client.c | 6 +++--- | |
M src/dopewars.c | 22 +++++++++++----------- | |
M src/gtkport/gtkport.c | 2 +- | |
M src/gui_client/gtk_client.c | 12 ++++++------ | |
M src/gui_client/newgamedia.c | 7 ++++--- | |
M src/network.c | 12 ++++++------ | |
M src/serverside.c | 20 ++++++++++---------- | |
M src/sound.c | 2 +- | |
8 files changed, 42 insertions(+), 41 deletions(-) | |
--- | |
diff --git a/src/curses_client/curses_client.c b/src/curses_client/curses_clien… | |
t@@ -649,14 +649,14 @@ static gboolean ConnectToServer(Player *Play) | |
errstr = g_string_new(""); | |
- if (g_strcasecmp(ServerName, SN_META) == 0 || ConnectMethod == CM_META) { | |
+ if (g_ascii_strncasecmp(ServerName, SN_META, strlen(SN_META)) == 0 || Connec… | |
ConnectMethod = CM_META; | |
MetaOK = SelectServerFromMetaServer(Play, errstr); | |
- } else if (g_strcasecmp(ServerName, SN_PROMPT) == 0 || | |
+ } else if (g_ascii_strncasecmp(ServerName, SN_PROMPT, strlen(SN_PROMPT)) == … | |
ConnectMethod == CM_PROMPT) { | |
ConnectMethod = CM_PROMPT; | |
SelectServerManually(); | |
- } else if (g_strcasecmp(ServerName, SN_SINGLE) == 0 || | |
+ } else if (g_ascii_strncasecmp(ServerName, SN_SINGLE, strlen(SN_SINGLE)) == … | |
ConnectMethod == CM_SINGLE) { | |
ConnectMethod = CM_SINGLE; | |
g_string_free(errstr, TRUE); | |
diff --git a/src/dopewars.c b/src/dopewars.c | |
t@@ -1406,18 +1406,18 @@ int GetNextDrugIndex(int OldIndex, Player *Play) | |
if (Play->Drugs[i].Price != 0 && i != OldIndex && i != MaxIndex && | |
(MaxIndex == -1 | |
|| (DrugSortMethod == DS_ATOZ | |
- && g_strcasecmp(Drug[MaxIndex].Name, Drug[i].Name) > 0) | |
+ && g_ascii_strncasecmp(Drug[MaxIndex].Name, Drug[i].Name, strlen(Dru… | |
|| (DrugSortMethod == DS_ZTOA | |
- && g_strcasecmp(Drug[MaxIndex].Name, Drug[i].Name) < 0) | |
+ && g_ascii_strncasecmp(Drug[MaxIndex].Name, Drug[i].Name, strlen(Dru… | |
|| (DrugSortMethod == DS_CHEAPFIRST | |
&& Play->Drugs[MaxIndex].Price > Play->Drugs[i].Price) | |
|| (DrugSortMethod == DS_CHEAPLAST | |
&& Play->Drugs[MaxIndex].Price < Play->Drugs[i].Price)) && | |
(OldIndex == -1 | |
|| (DrugSortMethod == DS_ATOZ | |
- && g_strcasecmp(Drug[OldIndex].Name, Drug[i].Name) <= 0) | |
+ && g_ascii_strncasecmp(Drug[OldIndex].Name, Drug[i].Name, strlen(Dru… | |
|| (DrugSortMethod == DS_ZTOA | |
- && g_strcasecmp(Drug[OldIndex].Name, Drug[i].Name) >= 0) | |
+ && g_ascii_strncasecmp(Drug[OldIndex].Name, Drug[i].Name, strlen(Dru… | |
|| (DrugSortMethod == DS_CHEAPFIRST | |
&& Play->Drugs[OldIndex].Price <= Play->Drugs[i].Price) | |
|| (DrugSortMethod == DS_CHEAPLAST | |
t@@ -1909,7 +1909,7 @@ gboolean ParseNextConfig(GScanner *scanner, Converter *c… | |
return FALSE; | |
} | |
- if (g_strcasecmp(scanner->value.v_identifier, "include") == 0) { | |
+ if (g_ascii_strncasecmp(scanner->value.v_identifier, "include", 7) == 0) { | |
token = g_scanner_get_next_token(scanner); | |
if (token == G_TOKEN_STRING) { | |
if (!ReadConfigFile(scanner->value.v_string, NULL)) { | |
t@@ -1922,7 +1922,7 @@ gboolean ParseNextConfig(GScanner *scanner, Converter *c… | |
NULL, NULL, FALSE); | |
return FALSE; | |
} | |
- } else if (g_strcasecmp(scanner->value.v_identifier, "encoding") == 0) { | |
+ } else if (g_ascii_strncasecmp(scanner->value.v_identifier, "encoding", 8) =… | |
token = g_scanner_get_next_token(scanner); | |
if (token == G_TOKEN_STRING) { | |
Conv_SetCodeset(conv, scanner->value.v_string); | |
t@@ -2002,13 +2002,13 @@ int GetGlobalIndex(gchar *ID1, gchar *ID2) | |
if (!ID1) | |
return -1; | |
for (i = 0; i < NumGlob; i++) { | |
- if (g_strcasecmp(ID1, Globals[i].Name) == 0 | |
+ if (g_ascii_strncasecmp(ID1, Globals[i].Name, strlen(Globals[i].Name)) == 0 | |
&& !Globals[i].NameStruct[0]) { | |
/* Just a bog-standard ID1=value */ | |
return i; | |
} | |
- if (g_strcasecmp(ID1, Globals[i].NameStruct) == 0 && ID2 | |
- && g_strcasecmp(ID2, Globals[i].Name) == 0 | |
+ if (g_ascii_strncasecmp(ID1, Globals[i].NameStruct, strlen(Globals[i].Name… | |
+ && g_ascii_strncasecmp(ID2, Globals[i].Name, strlen(Globals[i].Name)) … | |
&& Globals[i].StructStaticPt && Globals[i].StructListPt) { | |
/* ID1[index].ID2=value */ | |
return i; | |
t@@ -2242,11 +2242,11 @@ static gboolean SetConfigValue(int GlobalIndex, int St… | |
G_CSET_a_2_z "._0123456789" G_CSET_A_2_Z; | |
parsed = FALSE; | |
if (token == G_TOKEN_IDENTIFIER) { | |
- if (g_strcasecmp(scanner->value.v_identifier, "TRUE") == 0 || | |
+ if (g_ascii_strncasecmp(scanner->value.v_identifier, "TRUE", 4) == 0 || | |
strcmp(scanner->value.v_identifier, "1") == 0) { | |
parsed = TRUE; | |
*GetGlobalBoolean(GlobalIndex, StructIndex) = TRUE; | |
- } else if (g_strcasecmp(scanner->value.v_identifier, "FALSE") == 0 | |
+ } else if (g_ascii_strncasecmp(scanner->value.v_identifier, "FALSE", 5) … | |
|| strcmp(scanner->value.v_identifier, "0") == 0) { | |
parsed = TRUE; | |
*GetGlobalBoolean(GlobalIndex, StructIndex) = FALSE; | |
diff --git a/src/gtkport/gtkport.c b/src/gtkport/gtkport.c | |
t@@ -5613,7 +5613,7 @@ gint GtkMessageBox(GtkWidget *parent, const gchar *Text, | |
dialog = gtk_message_dialog_new(GTK_WINDOW(parent), | |
GTK_DIALOG_MODAL, | |
- type, buttons, Text); | |
+ type, buttons, "%s", Text); | |
if (Title) gtk_window_set_title(GTK_WINDOW(dialog), Title); | |
retval = gtk_dialog_run(GTK_DIALOG(dialog)); | |
diff --git a/src/gui_client/gtk_client.c b/src/gui_client/gtk_client.c | |
t@@ -1560,8 +1560,8 @@ static void UpdateDealDialog(void) | |
MaxDrug = CanDrop; | |
} | |
- spin_adj = (GtkAdjustment *)gtk_adjustment_new(MaxDrug, 1.0, MaxDrug, | |
- 1.0, 10.0, 10.0); | |
+ spin_adj = (GtkAdjustment *)gtk_adjustment_new(MaxDrug, 0.0, MaxDrug, | |
+ 1.0, 10.0, 0.0); | |
gtk_spin_button_set_adjustment(GTK_SPIN_BUTTON(DealDialog.amount), | |
spin_adj); | |
gtk_spin_button_set_value(GTK_SPIN_BUTTON(DealDialog.amount), MaxDrug); | |
t@@ -1735,8 +1735,8 @@ void DealDrugs(GtkWidget *widget, gpointer data) | |
} | |
label = gtk_label_new(text->str); | |
gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0); | |
- spin_adj = (GtkAdjustment *)gtk_adjustment_new(1.0, 1.0, 2.0, | |
- 1.0, 10.0, 10.0); | |
+ spin_adj = (GtkAdjustment *)gtk_adjustment_new(1.0, 0.0, 2.0, | |
+ 1.0, 10.0, 0.0); | |
spinner = DealDialog.amount = gtk_spin_button_new(spin_adj, 1.0, 0); | |
gtk_signal_connect(GTK_OBJECT(spinner), "activate", | |
GTK_SIGNAL_FUNC(DealOKCallback), data); | |
t@@ -2013,9 +2013,9 @@ static gint DrugSortFunc(GtkCList *clist, gconstpointer … | |
switch (DrugSortMethod) { | |
case DS_ATOZ: | |
- return g_strcasecmp(Drug[index1].Name, Drug[index2].Name); | |
+ return g_ascii_strncasecmp(Drug[index1].Name, Drug[index2].Name, strlen(Dr… | |
case DS_ZTOA: | |
- return g_strcasecmp(Drug[index2].Name, Drug[index1].Name); | |
+ return g_ascii_strncasecmp(Drug[index2].Name, Drug[index1].Name, strlen(Dr… | |
case DS_CHEAPFIRST: | |
pricediff = ClientData.Play->Drugs[index1].Price - | |
ClientData.Play->Drugs[index2].Price; | |
diff --git a/src/gui_client/newgamedia.c b/src/gui_client/newgamedia.c | |
t@@ -24,6 +24,7 @@ | |
#include <config.h> | |
#endif | |
+#include <string.h> | |
#include <stdlib.h> /* For atoi */ | |
#include <glib.h> | |
t@@ -527,12 +528,12 @@ void NewGameDialog(Player *play) | |
entry = stgam.hostname = gtk_entry_new(); | |
ServerEntry = "localhost"; | |
- if (g_strcasecmp(ServerName, SN_META) == 0) { | |
+ if (g_ascii_strncasecmp(ServerName, SN_META, strlen(SN_META)) == 0) { | |
NewGameType = 2; | |
UpdateMeta = TRUE; | |
- } else if (g_strcasecmp(ServerName, SN_PROMPT) == 0) | |
+ } else if (g_ascii_strncasecmp(ServerName, SN_PROMPT, strlen(SN_PROMPT)) == … | |
NewGameType = 0; | |
- else if (g_strcasecmp(ServerName, SN_SINGLE) == 0) | |
+ else if (g_ascii_strncasecmp(ServerName, SN_SINGLE, strlen(SN_SINGLE)) == 0) | |
NewGameType = 1; | |
else | |
ServerEntry = ServerName; | |
diff --git a/src/network.c b/src/network.c | |
t@@ -1295,7 +1295,7 @@ static gboolean ParseHtmlLocation(gchar *uri, gchar **ho… | |
gchar *uris, *colon, *slash; | |
uris = g_strstrip(uri); | |
- if (!uris || strlen(uris) < 7 || g_strncasecmp(uris, "http://", 7) != 0) | |
+ if (!uris || strlen(uris) < 7 || g_ascii_strncasecmp(uris, "http://", 7) != … | |
return FALSE; | |
uris += 7; /* skip to hostname */ | |
t@@ -1345,8 +1345,8 @@ static void StartHttpAuth(HttpConnection *conn, gboolean… | |
split = g_strsplit(header, " ", 2); | |
- if (split[0] && split[1] && g_strcasecmp(split[0], "Basic") == 0 && | |
- g_strncasecmp(split[1], "realm=", 6) == 0 && strlen(split[1]) > 6) { | |
+ if (split[0] && split[1] && g_ascii_strncasecmp(split[0], "Basic", 5) == 0 && | |
+ g_ascii_strncasecmp(split[1], "realm=", 6) == 0 && strlen(split[1]) > 6)… | |
realm = &split[1][6]; | |
conn->waitinput = TRUE; | |
(*conn->authfunc) (conn, proxy, realm, conn->authdata); | |
t@@ -1366,7 +1366,7 @@ static void ParseHtmlHeader(gchar *line, HttpConnection … | |
split = g_strsplit(line, " ", 2); | |
if (split[0] && split[1]) { | |
- if (g_strcasecmp(split[0], "Location:") == 0 && | |
+ if (g_ascii_strncasecmp(split[0], "Location:", 9) == 0 && | |
(conn->StatusCode == HEC_MOVETEMP | |
|| conn->StatusCode == HEC_MOVEPERM)) { | |
if (ParseHtmlLocation(split[1], &host, &port, &query)) { | |
t@@ -1380,10 +1380,10 @@ static void ParseHtmlHeader(gchar *line, HttpConnectio… | |
SetError(&conn->NetBuf.error, ÐTTP, HEC_BADREDIR, | |
g_strdup(line)); | |
} | |
- } else if (g_strcasecmp(split[0], "WWW-Authenticate:") == 0 && | |
+ } else if (g_ascii_strncasecmp(split[0], "WWW-Authenticate:", 17) == 0 && | |
conn->StatusCode == HEC_AUTHREQ) { | |
StartHttpAuth(conn, FALSE, split[1], doneOK); | |
- } else if (g_strcasecmp(split[0], "Proxy-Authenticate:") == 0 && | |
+ } else if (g_ascii_strncasecmp(split[0], "Proxy-Authenticate:", 19) == 0 && | |
conn->StatusCode == HEC_PROXYAUTH) { | |
/* Proxy-Authenticate is, strictly speaking, an HTTP/1.1 thing, but | |
* some HTTP/1.0 proxies seem to support it anyway */ | |
diff --git a/src/serverside.c b/src/serverside.c | |
t@@ -1000,18 +1000,18 @@ static void HandleServerCommand(char *string, NetworkB… | |
} | |
g_scanner_input_text(Scanner, string, strlen(string)); | |
if (!ParseNextConfig(Scanner, conv, NULL, TRUE)) { | |
- if (g_strcasecmp(string, "help") == 0 || g_strcasecmp(string, "h") == 0 | |
+ if (g_ascii_strncasecmp(string, "help", 4) == 0 || g_ascii_strncasecmp(str… | |
|| strcmp(string, "?") == 0) { | |
ServerHelp(); | |
- } else if (g_strcasecmp(string, "quit") == 0) { | |
+ } else if (g_ascii_strncasecmp(string, "quit", 4) == 0) { | |
RequestServerShutdown(); | |
- } else if (g_strncasecmp(string, "msg:", 4) == 0) { | |
+ } else if (g_ascii_strncasecmp(string, "msg:", 4) == 0) { | |
BroadcastToClients(C_NONE, C_MSG, string + 4, NULL, NULL); | |
- } else if (g_strncasecmp(string, "save ", 5) == 0) { | |
+ } else if (g_ascii_strncasecmp(string, "save ", 5) == 0) { | |
ServerSaveConfigFile(string + 5); | |
- } else if (g_strcasecmp(string, "save") == 0) { | |
+ } else if (g_ascii_strncasecmp(string, "save", 4) == 0) { | |
ServerSaveConfigFile(NULL); | |
- } else if (g_strcasecmp(string, "list") == 0) { | |
+ } else if (g_ascii_strncasecmp(string, "list", 4) == 0) { | |
if (FirstServer) { | |
g_print(_("Users currently logged on:-\n")); | |
for (list = FirstServer; list; list = g_slist_next(list)) { | |
t@@ -1022,14 +1022,14 @@ static void HandleServerCommand(char *string, NetworkB… | |
} | |
} else | |
g_print(_("No users currently logged on!\n")); | |
- } else if (g_strncasecmp(string, "push ", 5) == 0) { | |
+ } else if (g_ascii_strncasecmp(string, "push ", 5) == 0) { | |
tmp = GetPlayerByName(string + 5, FirstServer); | |
if (tmp) { | |
g_print(_("Pushing %s\n"), GetPlayerName(tmp)); | |
SendServerMessage(NULL, C_NONE, C_PUSH, tmp, NULL); | |
} else | |
g_print(_("No such user!\n")); | |
- } else if (g_strncasecmp(string, "kill ", 5) == 0) { | |
+ } else if (g_ascii_strncasecmp(string, "kill ", 5) == 0) { | |
tmp = GetPlayerByName(string + 5, FirstServer); | |
if (tmp) { | |
/* The named user has been removed from the server following | |
t@@ -1050,13 +1050,13 @@ static void HandleServerCommand(char *string, NetworkB… | |
Player *HandleNewConnection(void) | |
{ | |
- int cadsize; | |
+ socklen_t cadsize; | |
int ClientSock; | |
struct sockaddr_in ClientAddr; | |
Player *tmp; | |
cadsize = sizeof(struct sockaddr); | |
if ((ClientSock = accept(ListenSock, (struct sockaddr *)&ClientAddr, | |
- &cadsize)) == -1) { | |
+ &cadsize)) == -1) { | |
perror("accept socket"); | |
exit(EXIT_FAILURE); | |
} | |
diff --git a/src/sound.c b/src/sound.c | |
t@@ -190,7 +190,7 @@ void SoundOpen(gchar *drivername) | |
err = g_strdup_printf(_("Invalid plugin \"%s\" selected.\n" | |
"(%s available; now using \"%s\".)"), | |
drivername, plugins, NOPLUGIN); | |
- g_log(NULL, G_LOG_LEVEL_CRITICAL, err); | |
+ g_log(NULL, G_LOG_LEVEL_CRITICAL, "%s", err); | |
g_free(plugins); | |
g_free(err); | |
} |