From a8427ef33ab77eeb865003e5b62b6bb433550d10 Mon Sep 17 00:00:00 2001 From: jacob1 Date: Tue, 26 Apr 2016 23:55:14 -0400 Subject: [PATCH] only use -Wno-unused-result on Linux, also actually fix the unused results that we could possibly care about Fixes cross compilers, TODO: I don't think scons can check if a flag exists but might support adding a test for that, even if through hacky means, like CheckFramework --- SConscript | 4 +++- src/Misc.cpp | 33 ++++++--------------------------- src/Misc.h | 4 ---- src/client/Client.cpp | 19 ++++++++++--------- 4 files changed, 19 insertions(+), 41 deletions(-) diff --git a/SConscript b/SConscript index 48d479793..78815326a 100644 --- a/SConscript +++ b/SConscript @@ -388,7 +388,9 @@ if not msvc: env.Append(CXXFLAGS=['-std=gnu++98']) else: env.Append(CXXFLAGS=['-std=c++98']) - env.Append(CXXFLAGS=['-Wno-invalid-offsetof', '-Wno-unused-result']) + env.Append(CXXFLAGS=['-Wno-invalid-offsetof']) + if platform == "Linux": + env.Append(CXXFLAGS=['-Wno-unused-result']) #Add platform specific flags and defines diff --git a/src/Misc.cpp b/src/Misc.cpp index 0c291f9c2..ed7c191c7 100644 --- a/src/Misc.cpp +++ b/src/Misc.cpp @@ -75,32 +75,6 @@ void strlist_free(struct strlist **list) } } -void save_string(FILE *f, char *str) -{ - int li = strlen(str); - unsigned char lb[2]; - lb[0] = li; - lb[1] = li >> 8; - fwrite(lb, 2, 1, f); - fwrite(str, li, 1, f); -} - -int load_string(FILE *f, char *str, int max) -{ - int li; - unsigned char lb[2]; - fread(lb, 2, 1, f); - li = lb[0] | (lb[1] << 8); - if (li > max) - { - str[0] = 0; - return 1; - } - fread(str, li, 1, f); - str[li] = 0; - return 0; -} - const static char hex[] = "0123456789ABCDEF"; void strcaturl(char *dst, char *src) { @@ -155,8 +129,13 @@ void *file_load(char *fn, int *size) fclose(f); return NULL; } - fread(s, *size, 1, f); + int readsize = fread(s, *size, 1, f); fclose(f); + if (readsize != *size) + { + free(s); + return NULL; + } return s; } diff --git a/src/Misc.h b/src/Misc.h index 3e211e328..3fde885e7 100644 --- a/src/Misc.h +++ b/src/Misc.h @@ -54,10 +54,6 @@ void save_presets(int do_update); void load_presets(void); -void save_string(FILE *f, char *str); - -int load_string(FILE *f, char *str, int max); - void strcaturl(char *dst, const char *src); void strappend(char *dst, const char *src); diff --git a/src/client/Client.cpp b/src/client/Client.cpp index 561a759b6..a657fe39e 100644 --- a/src/client/Client.cpp +++ b/src/client/Client.cpp @@ -348,6 +348,7 @@ bool Client::DoInstallation() #elif defined(LIN) #include "icondoc.h" + int success == 1; std::string filename = Platform::ExecutableName(), pathname = filename.substr(0, filename.rfind('/')); for (size_t i = 0; i < filename.size(); i++) { @@ -391,7 +392,7 @@ bool Client::DoInstallation() return 0; fwrite(protocolfiledata.str().c_str(), 1, strlen(protocolfiledata.str().c_str()), f); fclose(f); - system("xdg-desktop-menu install powdertoy-tpt-ptsave.desktop"); + success = system("xdg-desktop-menu install powdertoy-tpt-ptsave.desktop"); const char *desktopfiledata_tmp = "[Desktop Entry]\n" @@ -408,8 +409,8 @@ bool Client::DoInstallation() return 0; fwrite(desktopfiledata.str().c_str(), 1, strlen(desktopfiledata.str().c_str()), f); fclose(f); - system("xdg-mime install powdertoy-save.xml"); - system("xdg-desktop-menu install powdertoy-tpt.desktop"); + success = system("xdg-mime install powdertoy-save.xml") && success; + success = system("xdg-desktop-menu install powdertoy-tpt.desktop") && success; f = fopen("powdertoy-save-32.png", "wb"); if (!f) return 0; @@ -420,17 +421,17 @@ bool Client::DoInstallation() return 0; fwrite(icon_doc_16_png, 1, sizeof(icon_doc_16_png), f); fclose(f); - system("xdg-icon-resource install --noupdate --context mimetypes --size 32 powdertoy-save-32.png application-vnd.powdertoy.save"); - system("xdg-icon-resource install --noupdate --context mimetypes --size 16 powdertoy-save-16.png application-vnd.powdertoy.save"); - system("xdg-icon-resource forceupdate"); - system("xdg-mime default powdertoy-tpt.desktop application/vnd.powdertoy.save"); - system("xdg-mime default powdertoy-tpt-ptsave.desktop x-scheme-handler/ptsave"); + success = system("xdg-icon-resource install --noupdate --context mimetypes --size 32 powdertoy-save-32.png application-vnd.powdertoy.save") && success; + success = system("xdg-icon-resource install --noupdate --context mimetypes --size 16 powdertoy-save-16.png application-vnd.powdertoy.save") && success; + success = system("xdg-icon-resource forceupdate") && success; + success = system("xdg-mime default powdertoy-tpt.desktop application/vnd.powdertoy.save") && success; + success = system("xdg-mime default powdertoy-tpt-ptsave.desktop x-scheme-handler/ptsave") && success; unlink("powdertoy-save-32.png"); unlink("powdertoy-save-16.png"); unlink("powdertoy-save.xml"); unlink("powdertoy-tpt.desktop"); unlink("powdertoy-tpt-ptsave.desktop"); - return true; + return !success; #elif defined MACOSX return false; #endif