From d5db35b86110d34e0446d67d77efb14f7e96a4d1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juhani=20Krekel=C3=A4?= Date: Tue, 20 Apr 2021 16:07:27 +0300 Subject: [PATCH] Fix assorted GCC warnings --- chimera/WWW.c | 5 ++++- chimera/bookmark.c | 4 ++-- chimera/cmisc.c | 1 + chimera/head.c | 11 ++++++++--- chimera/io.c | 2 -- chimera/main.c | 12 +++++++++--- chimera/source.c | 1 - chimera/stack.c | 9 ++++++++- chimera/view.c | 21 +++++++++++++++++++-- common/dmem.c | 1 + common/uproc.c | 21 +++------------------ html/form.c | 26 ++++++++++---------------- html/module.c | 2 +- html/table.c | 4 ++-- image/colorcube.c | 9 ++++++++- image/image.c | 3 +-- image/png.c | 1 + image/xbm.c | 2 ++ image/xcolorcube.c | 4 ++-- mxw/TextField.c | 13 ++++++++++--- proto/http.c | 9 +++++---- 21 files changed, 97 insertions(+), 64 deletions(-) diff --git a/chimera/WWW.c b/chimera/WWW.c index 97f2166..5d853c9 100644 --- a/chimera/WWW.c +++ b/chimera/WWW.c @@ -48,6 +48,7 @@ in this Software without prior written authorization from the X Consortium. #include "port_before.h" #include +#include #ifdef HAVE_STDLIB_H #include @@ -401,7 +402,9 @@ XtPointer call_data; { WWWWidget rw = (WWWWidget)XtParent(widget); register Widget child = rw->www.child; - int pix = (int)call_data; + // This is safe since we pass that data into here ourselves and it is + // originally of type int + int pix = (intptr_t)call_data; Position x, y; if (child == NULL) return; /* no child to scroll. */ diff --git a/chimera/bookmark.c b/chimera/bookmark.c index 41a2a30..2105345 100644 --- a/chimera/bookmark.c +++ b/chimera/bookmark.c @@ -199,7 +199,7 @@ BookmarkContext bc; if ((fp = fopen(bc->filename, "w")) != NULL) { - fprintf (fp, bc->header); + fprintf (fp, "%s", bc->header); fprintf (fp, "\n"); for (g = (BGroup *)GListGetHead(bc->glist); g != NULL; g = (BGroup *)GListGetNext(bc->glist)) @@ -212,7 +212,7 @@ BookmarkContext bc; } fprintf (fp, "\n"); } - fprintf (fp, bc->footer); + fprintf (fp, "%s", bc->footer); fprintf (fp, "\n"); fclose(fp); } diff --git a/chimera/cmisc.c b/chimera/cmisc.c index b84dba2..8577e41 100644 --- a/chimera/cmisc.c +++ b/chimera/cmisc.c @@ -21,6 +21,7 @@ #include "port_before.h" #include +#include #include #include diff --git a/chimera/head.c b/chimera/head.c index 372c8bb..f75fb45 100644 --- a/chimera/head.c +++ b/chimera/head.c @@ -23,6 +23,7 @@ #include "port_before.h" #include +#include #ifdef HAVE_UNISTD_H #include @@ -724,14 +725,18 @@ ChimeraRequest *lastresort; int count; MemPool mp; ChimeraRequest *wr = NULL; - char base_url[255]; + char base_url[PATH_MAX + 6]; /* * Default base URL; this allows filenames to be used on the * command line */ strcpy( base_url, "file:" ) ; - getcwd( base_url + 5, sizeof(base_url) - 5 ) ; + if (getcwd( base_url + 5, sizeof(base_url) - 5 ) == NULL) { + perror("getcwd failed"); + // Try using just the root of filesystem if we could not get cwd + strcat( base_url, "/" ) ; + } strcat( base_url, "/" ) ; ChimeraAddReference(cres); @@ -815,7 +820,7 @@ ChimeraRequest *lastresort; wr = RequestCreate(wc->cres, "file:/", NULL); } - myassert(wr != NULL, "ERROR: No valud URLs found for new head.\n"); + myassert(wr != NULL, "ERROR: No valid URLs found for new head.\n"); StackOpen(wc->tstack, wr); diff --git a/chimera/io.c b/chimera/io.c index fcd53a6..11420fa 100644 --- a/chimera/io.c +++ b/chimera/io.c @@ -366,9 +366,7 @@ ChimeraResources cres; ChimeraStream ps; int s; struct sockaddr_in6 addr; - struct hostent *hp; int namlen; - char host[BUFSIZ]; s = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); if (s < 0) return(NULL); diff --git a/chimera/main.c b/chimera/main.c index f6c38ec..d22f0c2 100644 --- a/chimera/main.c +++ b/chimera/main.c @@ -21,6 +21,7 @@ #include #include +#include #ifdef HAVE_STDLIB_H #include @@ -54,12 +55,12 @@ extern char *fallback_resources[]; static ChimeraResources globalcres; -void +int main(argc, argv) int argc; char **argv; { - char base_url[255]; + char base_url[PATH_MAX + 6]; signal(SIGINT, sigigh_handler); signal(SIGQUIT, sigigh_handler); @@ -76,7 +77,10 @@ char **argv; * command line */ strcpy( base_url, "file:" ) ; - getcwd( base_url + 5, sizeof(base_url) - 5 ) ; + if (getcwd( base_url + 5, sizeof(base_url) - 5 ) == NULL) { + perror("getcwd failed"); + return 1; + } strcat( base_url, "/" ) ; if (argc > 1) HeadCreate(globalcres, @@ -88,6 +92,8 @@ char **argv; * And away we go... */ XtAppMainLoop(globalcres->appcon); + + return 0; } /* diff --git a/chimera/source.c b/chimera/source.c index c3b2c79..45bdec7 100644 --- a/chimera/source.c +++ b/chimera/source.c @@ -374,7 +374,6 @@ ChimeraResources cres; ChimeraRequest *wr; { ChimeraSource ws; - char *content; /* * Input data can make the output different everytime don't even diff --git a/chimera/stack.c b/chimera/stack.c index 3da712b..aa452a0 100644 --- a/chimera/stack.c +++ b/chimera/stack.c @@ -399,7 +399,14 @@ void *closure; cs->wp, rh, NULL, NULL, u->state, cs->rap, cs->rapc)) == NULL) { - DownloadOpen(cs->wc->cres, wr); + if ((wr = RequestCreate(cs->wc->cres, url, NULL)) == NULL) + { + HeadPrintMessage(cs->wc, "Invalid URL."); + } + else + { + DownloadOpen(cs->wc->cres, wr); + } SinkDestroy(wp); return(-1); } diff --git a/chimera/view.c b/chimera/view.c index a0b5a95..e3ec725 100644 --- a/chimera/view.c +++ b/chimera/view.c @@ -19,6 +19,7 @@ */ #include "port_before.h" +#include #include #ifdef HAVE_STDLIB_H @@ -157,7 +158,23 @@ void *closure; strcat(final, "; rm "); strcat(final, filename); strcat(final, ") &"); - system(final); + int status = system(final); + if (status == -1) + { + perror("system"); + } + else if (status != 0) + { + assert(WIFEXITED(status) || WIFSIGNALED(status)); + if (WIFEXITED(status)) + { + fprintf(stderr, "Cleanup failed, return code %i\n", WEXITSTATUS(status)); + } + else if(WIFSIGNALED(status)) + { + fprintf(stderr, "Cleanup failed, child died from signal %i\n", WTERMSIG(status)); + } + } } ViewDestroy(vi); @@ -285,7 +302,7 @@ ViewInfo *vi; box = XtCreateManagedWidget("box2", boxWidgetClass, paned, NULL, 0); - stop = XtVaCreateManagedWidget("stop", commandWidgetClass, box, NULL, 0); + stop = XtCreateManagedWidget("stop", commandWidgetClass, box, NULL, 0); XtAddCallback(stop, XtNcallback, ViewDialogStop, vi); diff --git a/common/dmem.c b/common/dmem.c index a3cbeb6..38e5b0b 100644 --- a/common/dmem.c +++ b/common/dmem.c @@ -21,6 +21,7 @@ #include "port_before.h" #include +#include #ifdef HAVE_STDLIB_H #include diff --git a/common/uproc.c b/common/uproc.c index bdf4e68..a10c37e 100644 --- a/common/uproc.c +++ b/common/uproc.c @@ -87,24 +87,20 @@ StartReaper() * PipeCommand * * fork and exec to get a program running and supply it with - * a stdin, stdout, stderr that so we can talk to it. + * a stdin so that we can talk to it. + * ^ Used to supply stdout/stderr too, but that was commented out before + * I got here -nortti, 2021 */ int PipeCommand(command, fd) char *command; int *fd; { - int pout[2]; int pin[2]; int pid; -/* - if (pipe(pout) == -1) return(-1); -*/ if (pipe(pin) == -1) { - close(pout[0]); - close(pout[1]); return(-1); } @@ -115,13 +111,6 @@ int *fd; } else if (pid == 0) { -/* - if (pout[1] != 1) - { - dup2(pout[1], 1); - close(pout[1]); - } -*/ if (pin[0] != 0) { dup2(pin[0], 0); @@ -134,14 +123,10 @@ int *fd; } else { - close(pout[1]); close(pin[0]); } fd[0] = pin[1]; -/* - fd[1] = pout[0]; -*/ return(0); } diff --git a/html/form.c b/html/form.c index bc7ef13..9c9fc4c 100644 --- a/html/form.c +++ b/html/form.c @@ -554,7 +554,6 @@ InputType type; int width, height; XFontStruct *font; char *value; - HTMLBox box; InputState *ci; Boolean echo; char *name; @@ -601,7 +600,7 @@ InputType type; /* End: replaces "width = 100;" */ ci = CreateInputState(fs, p, type); - box = CreateInputBox(fs->li, env, ci, width, height); + CreateInputBox(fs->li, env, ci, width, height); ci->w = w; return; @@ -618,7 +617,6 @@ MLElement p; { Widget w; Boolean state; - HTMLBox box; InputState *ci; if (MLFindAttribute(p, "checked") != NULL) state = True; @@ -631,7 +629,7 @@ MLElement p; NULL); ci = CreateInputState(fs, p, INPUT_CHECKBOX); - box = CreateInputBox(fs->li, env, ci, 15, 15); + CreateInputBox(fs->li, env, ci, 15, 15); ci->w = w; return; @@ -650,7 +648,6 @@ MLElement p; Boolean state; char *name; InputState *ci, *peer; - HTMLBox box; if (MLFindAttribute(p, "checked") != NULL) state = True; else state = False; @@ -671,7 +668,7 @@ MLElement p; NULL); ci = CreateInputState(fs, p, INPUT_RADIO); - box = CreateInputBox(fs->li, env, ci, 15, 15); + CreateInputBox(fs->li, env, ci, 15, 15); ci->w = w; ci->name = (char *)MPStrDup(fs->li->mp, name); @@ -703,7 +700,6 @@ InputType type; Widget w; InputState *ci; char *name; - HTMLBox box; argcnt = 0; name = type == INPUT_SUBMIT ? "submit":"reset"; @@ -731,7 +727,7 @@ InputType type; height = font->ascent + font->descent + 3; } ci = CreateInputState(fs, p, type); - box = CreateInputBox(fs->li, env, ci, width, height); + CreateInputBox(fs->li, env, ci, width, height); ci->w = w; if (type == INPUT_SUBMIT) @@ -848,7 +844,6 @@ MLElement p; XFontStruct *font; int rows, cols; Widget w; - HTMLBox box; HTMLObject obj; if ((fenv = HTMLGetIDEnv(env, TAG_FORM)) == NULL) return; @@ -878,7 +873,7 @@ MLElement p; width *= cols; ci = CreateInputState(fs, obj->o.p, INPUT_TEXTAREA); - box = CreateInputBox(fs->li, env, ci, width, height); + CreateInputBox(fs->li, env, ci, width, height); ci->w = w; return; @@ -903,7 +898,6 @@ HTMLEnv env; int width, twidth; XFontStruct *font; Widget w, smw; - HTMLBox box; OptionState *c; GList oplist = fs->oplist; HTMLObject obj; @@ -949,8 +943,8 @@ HTMLEnv env; obj = (HTMLObject)GListGetHead(env->slist); ci = CreateInputState(fs, obj->o.p, INPUT_SELECT); - box = CreateInputBox(fs->li, env, ci, - width + 10, font->ascent + font->descent + 4); + CreateInputBox(fs->li, env, ci, + width + 10, font->ascent + font->descent + 4); ci->w = w; ci->oplist = oplist; @@ -1084,6 +1078,9 @@ MLElement p; if ((url = MLFindAttribute(p, "src")) == NULL) return; + ci = CreateInputState(fs, p, INPUT_IMAGE); + ci->img = HTMLCreateInline(fs->li, env, url, &ii, &orh, ci); + memset(&ii, 0, sizeof(ii)); ii.p = p; ii.closure = ci; @@ -1092,8 +1089,5 @@ MLElement p; orh.select = FormImageSelectCallback; orh.motion = FormImageMotionCallback; - ci = CreateInputState(fs, p, INPUT_IMAGE); - ci->img = HTMLCreateInline(fs->li, env, url, &ii, &orh, ci); - return; } diff --git a/html/module.c b/html/module.c index 8327cad..2fe6a43 100644 --- a/html/module.c +++ b/html/module.c @@ -477,7 +477,7 @@ ChimeraResources cres; char *cssfile; char *b; struct stat st; - size_t rval, blen; + size_t rval, blen=0; mp = MPCreate(); lc = (HTMLClass)MPCGet(mp, sizeof(struct HTMLClassP)); diff --git a/html/table.c b/html/table.c index c4749fb..3148164 100644 --- a/html/table.c +++ b/html/table.c @@ -354,9 +354,9 @@ MLElement p; char *value, *cp; int x; int border; - unsigned int width, maxwidth; + unsigned int width; - maxwidth = width = HTMLGetMaxWidth(li, env->penv); + width = HTMLGetMaxWidth(li, env->penv); env->ff = FLOW_LEFT_JUSTIFY; env->anchor = NULL; diff --git a/image/colorcube.c b/image/colorcube.c index 2f4526a..9fc7e31 100644 --- a/image/colorcube.c +++ b/image/colorcube.c @@ -40,6 +40,7 @@ #include "port_before.h" +#include #include #include "port_after.h" @@ -472,7 +473,12 @@ ccf_create_gray_conversion_table(cct_cube cube) { int j; int min_dist = 400000; /* big number ! */ - int min_entry; + // GCC complains about min_entry possibly not being set in the loop + // I'm not able to prove that it does, so set up a sentinel value and + // assert on it + // cube->u.grayscale.pixel_values is defined as pixel_values[256], so + // min_entry can never be 256 if it is a valid index + int min_entry = 256; for (j = 0; j < cube->u.grayscale.value_count; j++) { int dist; @@ -484,6 +490,7 @@ ccf_create_gray_conversion_table(cct_cube cube) min_entry = j; } } + assert(min_entry != 256); answer->pixel_values[i] = cube->u.grayscale.pixel_values[min_entry]; } return answer; diff --git a/image/image.c b/image/image.c index c486cfb..9d1bb54 100644 --- a/image/image.c +++ b/image/image.c @@ -1060,7 +1060,6 @@ void *state; /* ignored */ ImageState *is; int format; XWindowAttributes xwa; - int status; char *content; int i; ChimeraSink wp; @@ -1088,7 +1087,7 @@ void *state; /* ignored */ if (!ic->init) ImageClassInit(ic, is->dpy); - status = XGetWindowAttributes(is->dpy, is->win, &xwa); + XGetWindowAttributes(is->dpy, is->win, &xwa); is->v = xwa.visual; is->depth = xwa.depth; is->cmap = xwa.colormap; diff --git a/image/png.c b/image/png.c index 60636b6..a126830 100644 --- a/image/png.c +++ b/image/png.c @@ -5,6 +5,7 @@ #include "port_before.h" #include +#include #include "port_after.h" diff --git a/image/xbm.c b/image/xbm.c index ccd9659..afdf701 100644 --- a/image/xbm.c +++ b/image/xbm.c @@ -32,6 +32,7 @@ #include "imagep.h" #include "xbmp.h" +#ifdef CHIMERA_BIG_ENDIAN static byte lc_reverse_byte[] = { 0, 128, 64, 192, 32, 160, 96, 224, 16, 144, 80, 208, 48, 176, 112, 240, @@ -50,6 +51,7 @@ static byte lc_reverse_byte[] = 11, 139, 75, 203, 43, 171, 107, 235, 27, 155, 91, 219, 59, 187, 123, 251, 7, 135, 71, 199, 39, 167, 103, 231, 23, 151, 87, 215, 55, 183, 119, 247, 15, 143, 79, 207, 47, 175, 111, 239, 31, 159, 95, 223, 63, 191, 127, 255}; +#endif /* * xbmGetImage diff --git a/image/xcolorcube.c b/image/xcolorcube.c index 1c3c55a..5548487 100644 --- a/image/xcolorcube.c +++ b/image/xcolorcube.c @@ -450,7 +450,7 @@ xccf_allocate_special( int r = intensities[0] >> 8; int g = intensities[1] >> 8; int b = intensities[2] >> 8; - int gr; + //int gr; if(really_allocated_return) *really_allocated_return = false; if(cube) { @@ -489,7 +489,7 @@ xccf_allocate_special( break; } } - gr = (r + g + b) / 3; + //gr = (r + g + b) / 3; if(grayscale /* && xccf_color_compare(r,g,b,gr,gr,gr)*/) { for(i = 0; i < grayscale->u.grayscale.value_count; i++) diff --git a/mxw/TextField.c b/mxw/TextField.c index fdc0c36..ed9fbd4 100644 --- a/mxw/TextField.c +++ b/mxw/TextField.c @@ -29,6 +29,8 @@ #include #include +#include +#include #include #ifdef HAVE_STDLIB_H @@ -943,12 +945,14 @@ ConvertSelection(Widget aw, Atom * selection, Atom * target, Atom * type, XSelectionRequestEvent *req = XtGetSelectionRequest(aw, *selection, NULL); if (*target == XA_TARGETS(XtDisplay(aw))) { - Atom *targetP, *std_targets; + Atom *targetP; + char *std_targets; unsigned long std_length; XmuConvertStandardSelection(aw, req->time, selection, target, type, &std_targets, &std_length, format); + assert(*format == sizeof(Atom) * 8); *value = XtMalloc((unsigned) sizeof(Atom) * (std_length + 1)); targetP = *(Atom **) value; @@ -1027,7 +1031,8 @@ RequestSelection(Widget aw, XtPointer client, Atom * selection, Atom * type, ClearHighlight(w); savex = w->text.OldCursorX; - w->text.CursorPos = (int) client; + // This is safe because we passed this in as an int + w->text.CursorPos = (intptr_t) client; #ifdef DEBUG_TF printf("RequestSelection: inserting %s length=%d at pos: %d\n", (char *) value, (int) (*length), w->text.CursorPos); @@ -1052,9 +1057,11 @@ InsertSelection(Widget aw, XEvent * event, String * params, Cardinal * num_param #ifdef DEBUG_TF printf("InsertSelection: event at pos: %d\n", pos); #endif + // The cast to intptr_t assumes that pointers are at least as wide as + // ints are, which is pretty safe assumption XtGetSelectionValue(aw, XA_PRIMARY, XA_STRING, RequestSelection, - (XtPointer) pos, event->xbutton.time); + (XtPointer) (intptr_t)pos, event->xbutton.time); } diff --git a/proto/http.c b/proto/http.c index 915dceb..46df43c 100644 --- a/proto/http.c +++ b/proto/http.c @@ -354,7 +354,6 @@ ssize_t *len; const char *authfield = "Authorization: "; char *username; char *password; - URLParts *up; if (hi->hp == NULL) return(NULL); if (hi->hp->type == NULL || strcasecmp(hi->hp->type, "basic") != 0) @@ -364,7 +363,6 @@ ssize_t *len; username = hi->hp->username; password = hi->hp->password; - up = hi->up; line = (char *)MPGet(hi->rmp, strlen(authfield) + @@ -920,13 +918,16 @@ HTTPInfo **hip; { HTTPAuthCallback(hip, hi->up->username, hi->up->password); + username = NULL; } else username = hi->up->username; } else username = ""; - hi->wa = AuthCreate(hi->cres, "Enter password", username, - HTTPAuthCallback, hip); + if (username != NULL) { + hi->wa = AuthCreate(hi->cres, "Enter password", username, + HTTPAuthCallback, hip); + } /* * If the authorization context is created then return -1 to