From f775bcb13ceda65400948d2444d8adfa411a1a06 Mon Sep 17 00:00:00 2001 From: Scott Duensing Date: Wed, 26 Apr 2023 18:20:48 -0500 Subject: [PATCH] Warnings and low-hanging TODOs fixed. --- src/compiler.c | 5 ++++- src/editor.c | 25 ++++++++++++++++--------- src/joeydev.c | 1 + src/project.c | 10 ++++------ src/ssh.c | 2 +- src/utils.c | 18 ++++++++++-------- src/vector.c | 7 ++++--- 7 files changed, 40 insertions(+), 28 deletions(-) diff --git a/src/compiler.c b/src/compiler.c index 4718220..39e9eeb 100644 --- a/src/compiler.c +++ b/src/compiler.c @@ -86,7 +86,7 @@ int compilerRunRecipe(char *recipe, char *input, char *outputPath, void *context } // __resourcePath comes in with a trailing slash. Temporarily remove it. - x = strlen(__resourcePath) - 1; + x = (int)strlen(__resourcePath) - 1; c = __resourcePath[x]; __resourcePath[x] = 0; tcc_set_lib_path(s, __resourcePath); @@ -185,6 +185,9 @@ static void sigHandlerContinuation(void *arg1, void *arg2, void *arg3) { int sigHandler(void *faultAddress, int serious) { + (void)faultAddress; + (void)serious; + runPass++; return sigsegv_leave_handler(sigHandlerContinuation, NULL, NULL, NULL); } diff --git a/src/editor.c b/src/editor.c index 7caca52..01550cd 100644 --- a/src/editor.c +++ b/src/editor.c @@ -24,6 +24,7 @@ #include "editor.h" #include "utils.h" #include "scintillaHeaders.h" +#include "messages.h" #define MARKER_ERROR_ARROW 0 @@ -38,7 +39,7 @@ typedef struct EditorDataS { ScintillaObject *sci; void *pLexer; int id; - int statusBarId; + guint statusBarId; } EditorDataT; @@ -158,8 +159,8 @@ static void loadEditorConfig(char *lexer, EditorDataT *self) { // style number "tags" "description" ... (style keywords) c = utilGetToken(NULL, " ", "\"", "\""); number = strtol(c, NULL, 10); - c = utilGetToken(NULL, " ", "\"", "\""); - c = utilGetToken(NULL, " ", "\"", "\""); + utilGetToken(NULL, " ", "\"", "\""); + utilGetToken(NULL, " ", "\"", "\""); c = utilGetToken(NULL, " ", "\"", "\""); do { if (strcmp(c, "fore") == 0) { @@ -190,7 +191,7 @@ static void loadEditorConfig(char *lexer, EditorDataT *self) { type = strdup(c); c = utilGetToken(NULL, " ", "\"", "\""); name = strdup(c); - c = utilGetToken(NULL, " ", "\"", "\""); + utilGetToken(NULL, " ", "\"", "\""); c = utilGetToken(NULL, " ", "\"", "\""); utilDequote(c); SSM(SCI_SETPROPERTY, (sptr_t)name, (sptr_t)c); @@ -204,7 +205,7 @@ static void loadEditorConfig(char *lexer, EditorDataT *self) { // keywords number "description" wordlist c = utilGetToken(NULL, " ", "\"", "\""); number = strtol(c, NULL, 10); - c = utilGetToken(NULL, " ", "\"", "\""); + utilGetToken(NULL, " ", "\"", "\""); c = utilGetToken(NULL, "\n", "\"", "\""); if (c && strlen(c) > 0) SSM(SCI_SETKEYWORDS, number, (sptr_t)c); continue; @@ -314,7 +315,7 @@ EVENT void menuEditorFileSave(GtkWidget *object, gpointer userData) { // Allocate space to fetch code from editor. code = (char *)malloc(length + 1); if (!code) { - //***TODO*** Something bad happened. + message(MSG_SEVERE, "Unable to allocate code buffer during editor save!"); return; } @@ -330,7 +331,7 @@ EVENT void menuEditorFileSave(GtkWidget *object, gpointer userData) { // We're clean now. utilSetDirty((WindowDataT *)self, FALSE); } else { - //***TODO*** Something bad happened. + message(MSG_SEVERE, "Unknown error attempting to save %s!", self->windowData.filename); } // Release code. @@ -396,6 +397,8 @@ void winEditorCreate(char *filename) { NULL }; + //***TODO*** Be sure this is something we can edit as text. + // Set up instance data. self = NEW(EditorDataT); self->windowData.closeWindow = winEditorClose; @@ -501,8 +504,8 @@ static void writeEditorConfig(char *lexer, EditorDataT *self) { char *description = NULL; char *config = NULL; FILE *out = NULL; - int result = -1; - int size = -1; + int result; + int size; int x; config = utilCreateString("%s%cjoeydev%ceditor-%s.conf", g_get_user_config_dir(), UTIL_PATH_CHAR, UTIL_PATH_CHAR, lexer); @@ -574,6 +577,10 @@ static void writeEditorConfig(char *lexer, EditorDataT *self) { size = SSM(SCI_GETPROPERTYINT, (sptr_t)tags, 0); config = utilCreateString("%d", size); break; + + default: + message(MSG_SEVERE, "Unknown property type saving editor config!"); + break; } fprintf(out, " %s \"%s\" %s\n", tags, description, config); DEL(config); diff --git a/src/joeydev.c b/src/joeydev.c index f821e02..ca9ccd2 100644 --- a/src/joeydev.c +++ b/src/joeydev.c @@ -96,6 +96,7 @@ EVENT void toolJoeyDevVectorClicked(GtkWidget *widget, gpointer userData) { EVENT gboolean winJoeyDevClose(GtkWidget *widget, gpointer userData) { + (void)widget; (void)userData; // Do they want to quit? diff --git a/src/project.c b/src/project.c index 9583b4a..1434aed 100644 --- a/src/project.c +++ b/src/project.c @@ -170,8 +170,6 @@ EVENT void btnEditRawClicked(GtkButton *widget, gpointer userData) { gtk_dialog_response(GTK_DIALOG(self->tempWidget), GTK_RESPONSE_CANCEL); - //***TODO*** Be sure this is something we can edit as text. - filename = utilCreateString("%s%s", self->windowData.path, gtk_label_get_text(GTK_LABEL(lblRaw))); winEditorCreate(filename); DEL(filename); @@ -370,7 +368,7 @@ static void loadConfig(ProjectDataT *self) { fclose(in); DEL(line); } else { - //***TODO*** Something bad happened. + message(MSG_SEVERE, "Unknown error attempting to load build configuration!"); } } else { // No config file. Set defaults. @@ -475,7 +473,7 @@ static void loadProject(ProjectDataT *self) { DEL(line); utilSetDirty((WindowDataT *)self, FALSE); // Do again - loading text marks us dirty. } else { - //***TODO*** Something bad happened. + message(MSG_SEVERE, "Unknown error attempting to load %s!", self->windowData.filename); } } @@ -596,7 +594,7 @@ EVENT void menuProjectFileSave(GtkWidget *object, gpointer userData) { // We're clean now. utilSetDirty((WindowDataT *)self, FALSE); } else { - //***TODO*** Something bad happened. + message(MSG_SEVERE, "Unknown error attempting to save %s!", self->windowData.filename); } } } @@ -1023,7 +1021,7 @@ static void saveConfig(ProjectDataT *self) { DEL(temp); fclose(out); } else { - //***TODO*** Something bad happened. + message(MSG_SEVERE, "Unknown error attempting to save build configuration!"); } } diff --git a/src/ssh.c b/src/ssh.c index 87aa2e7..efe782f 100644 --- a/src/ssh.c +++ b/src/ssh.c @@ -155,7 +155,7 @@ int sshExecute(SSHT *sshData, char *command, char **output) { do { rc = libssh2_channel_read(sshData->channel, (char *)_buffer, sizeof(_buffer)); if (rc > 0) { - utilEnsureBufferSize((unsigned char **)output, &outputLen, strlen((const char *)*output) + rc + 1); + utilEnsureBufferSize((unsigned char **)output, &outputLen, (int)strlen((const char *)*output) + rc + 1); strncat(*output, (char *)_buffer, rc); } } while (rc > 0); diff --git a/src/utils.c b/src/utils.c index 15a94a7..24c72d9 100644 --- a/src/utils.c +++ b/src/utils.c @@ -25,6 +25,7 @@ #include "common.h" #include "utils.h" #include "cwalk.h" +#include "messages.h" #ifdef _WIN32 @@ -60,7 +61,7 @@ char *utilCreateString(char *format, ...) { __attribute__((__format__(__printf__, 1, 0))) char *utilCreateStringVArgs(char *format, va_list args) { va_list argsCopy; - int32_t size = 0; + int32_t size; char *buffer = NULL; va_copy(argsCopy, args); @@ -92,7 +93,7 @@ char *utilDeobfuscateASCII(char *obfuscated) { for (i=0; i= strlen(hostname)) j = 0; } @@ -123,7 +124,7 @@ void utilEnsureBufferSize(unsigned char **buffer, int *length, int wanted) { while (*length < wanted) *length = *length + 1024; temp = realloc(*buffer, *length); if (temp == NULL) { - //***TODO*** Something bad happened. + message(MSG_SEVERE, "Unable to reallocate buffer from %d to %d bytes!", *length, wanted); } else { *buffer = temp; } @@ -273,7 +274,7 @@ gboolean utilFileOpen(WindowDataT *self, char *extension, char *what) { char *utilFileRemoveExtension(char *filename) { int x = (int)strlen(filename) - 1; - char c = 0; + char c; char *newString = NULL; while (x >= 0) { @@ -376,7 +377,6 @@ GtkWidget *utilFindChildWidget(GtkWidget *parent, const gchar *name) { } -// https://stackoverflow.com/questions/26187037/in-c-split-char-on-spaces-with-strtok-function-except-if-between-quotes char *utilGetToken(char *input, char *delimit, char *openblock, char *closeblock) { static char *token = NULL; char *lead = NULL; @@ -384,6 +384,8 @@ char *utilGetToken(char *input, char *delimit, char *openblock, char *closeblock int iBlock = 0; int iBlockIndex = 0; + // https://stackoverflow.com/questions/26187037/in-c-split-char-on-spaces-with-strtok-function-except-if-between-quotes + if (input != NULL) { token = input; lead = input; @@ -404,7 +406,7 @@ char *utilGetToken(char *input, char *delimit, char *openblock, char *closeblock if ((block = strchr(openblock, *token)) != NULL) { iBlock = 1; - iBlockIndex = block - openblock; + iBlockIndex = (int)(block - openblock); token++; continue; } @@ -529,7 +531,7 @@ char *utilObfuscateASCII(char *clearText) { for (i=0; i 94) c -= 94; - obfuscated[i] = c + 32; + obfuscated[i] = (char)(c + 32); j++; if (j >= strlen(hostname)) j = 0; } @@ -628,7 +630,7 @@ int utilWindowsOpen(void) { gboolean utilWindowUnRegister(gpointer windowData) { - int result = 0; + int result; WindowDataT *w = (WindowDataT *)windowData; result = hmdel(_windowList, w->window); diff --git a/src/vector.c b/src/vector.c index 28299f2..f841926 100644 --- a/src/vector.c +++ b/src/vector.c @@ -38,6 +38,7 @@ #include "vecparse.h" #include "color.h" #include "palette.h" +#include "messages.h" //***TODO*** Reuse editor.c instead of using our own text editor here. @@ -668,7 +669,7 @@ static void loadVectorImage(VectorDataT *self) { status(self, "Image loaded."); utilSetDirty((WindowDataT *)self, FALSE); // Do again - loading text marks us dirty. } else { - //***TODO*** Something bad happened. + message(MSG_SEVERE, "Unknown error attempting to load %s!", self->windowData.filename); } } @@ -775,7 +776,7 @@ EVENT void menuVectorFileSave(GtkWidget *object, gpointer userData) { // Allocate space to fetch code from editor. code = (char *)malloc(length + 1); if (!code) { - //***TODO*** Something bad happened. + message(MSG_SEVERE, "Unable to allocate code buffer during vector save!"); return; } @@ -794,7 +795,7 @@ EVENT void menuVectorFileSave(GtkWidget *object, gpointer userData) { // We're clean now. utilSetDirty((WindowDataT *)self, FALSE); } else { - //***TODO*** Something bad happened. + message(MSG_SEVERE, "Unknown error attempting to write %s!", self->windowData.filename); } // Release code.