From 30e2e57a58c2bcccff5f0091a43e9bb953a42e18 Mon Sep 17 00:00:00 2001 From: Mike Small Date: Sun, 1 Oct 2017 00:02:51 -0400 Subject: [PATCH] Set warnings as errors. Const correct massaging to lose the couple warnings that were there. --- ChangeLog | 13 +++++++++++++ src/Makefile.am | 2 +- src/Makefile.in | 2 +- src/menus.c | 24 ++++++++++++------------ src/screen.h | 2 +- src/util.c | 20 ++++++++++---------- src/util.h | 2 +- 7 files changed, 39 insertions(+), 26 deletions(-) diff --git a/ChangeLog b/ChangeLog index 923018e..b261738 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,16 @@ +2017-09-30 Michael Small + + * src/Makefile.am (AM_CFLAGS): warnings as errors. + * src/menus.c (ExecuteFunction): ptr as const char* to prevent const + qualifier discard warnings when passed const char* action. + * src/util.c (ExpandFilename): use const char* for arg and return value. + (FindBitmap): cast return val of ExpandFilename to char* for bigname. + Should be harmless since it's used as constant data up to it being + assigned something else. + (GetFont): Similar case here but without ExpandFilename being involved. + * src/screen.h (ScreenInfo): IconDirectory can be const char* too, + avoiding warning in parse.c:771. + 2017-09-27 Michael Small Preliminaries: diff --git a/src/Makefile.am b/src/Makefile.am index 941d552..949e997 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -32,7 +32,7 @@ AM_CPPFLAGS = \ -DXORG_RELEASE=\"Release\ $(VERSION)\" \ -DSYSTEM_INIT_FILE=\"${datadir}/X11/twmruined/system.twmruinedrc\" -AM_CFLAGS = $(TWM_CFLAGS) +AM_CFLAGS = -Werror $(TWM_CFLAGS) twmruined_LDADD = $(TWM_LIBS) twmruined_SOURCES = \ diff --git a/src/Makefile.in b/src/Makefile.in index e85cfd2..19aa3f8 100644 --- a/src/Makefile.in +++ b/src/Makefile.in @@ -366,7 +366,7 @@ AM_CPPFLAGS = \ -DXORG_RELEASE=\"Release\ $(VERSION)\" \ -DSYSTEM_INIT_FILE=\"${datadir}/X11/twmruined/system.twmruinedrc\" -AM_CFLAGS = $(TWM_CFLAGS) +AM_CFLAGS = -Werror $(TWM_CFLAGS) twmruined_LDADD = $(TWM_LIBS) twmruined_SOURCES = \ add_window.c \ diff --git a/src/menus.c b/src/menus.c index e23b5ff..97985c9 100644 --- a/src/menus.c +++ b/src/menus.c @@ -1293,7 +1293,7 @@ ExecuteFunction(int func, const char *action, Window w, TwmWindow *tmp_win, { static Time last_time = 0; char tmp[200]; - char *ptr; + const char *ptr; char buff[MAX_FILE_SIZE]; int count, fd; Window rootw; @@ -2006,24 +2006,24 @@ ExecuteFunction(int func, const char *action, Window w, TwmWindow *tmp_win, case F_CUTFILE: ptr = XFetchBytes(dpy, &count); if (ptr) { - if (sscanf (ptr, "%s", tmp) == 1) { - XFree (ptr); + if (sscanf(ptr, "%s", tmp) == 1) { + XFree((void*)ptr); ptr = ExpandFilename(tmp); if (ptr) { - fd = open (ptr, O_RDONLY); + fd = open(ptr, O_RDONLY); if (fd >= 0) { - count = read (fd, buff, MAX_FILE_SIZE - 1); - if (count > 0) XStoreBytes (dpy, buff, count); + count = read(fd, buff, MAX_FILE_SIZE - 1); + if (count > 0) XStoreBytes(dpy, buff, count); close(fd); } else { - fprintf (stderr, - "%s: unable to open cut file \"%s\"\n", - ProgramName, tmp); + fprintf(stderr, + "%s: unable to open cut file \"%s\"\n", + ProgramName, tmp); } - if (ptr != tmp) free (ptr); + if (ptr != tmp) free((void*)ptr); } } else { - XFree(ptr); + XFree((void*)ptr); } } else { fprintf(stderr, "%s: cut buffer is empty\n", ProgramName); @@ -2185,7 +2185,7 @@ ExecuteFunction(int func, const char *action, Window w, TwmWindow *tmp_win, fprintf (stderr, "%s: unable to open file \"%s\"\n", ProgramName, ptr); } - if (ptr != action) free(ptr); + if (ptr != action) free((void*)ptr); break; case F_REFRESH: diff --git a/src/screen.h b/src/screen.h index 2798137..644ca43 100644 --- a/src/screen.h +++ b/src/screen.h @@ -195,7 +195,7 @@ typedef struct ScreenInfo IconMgr iconmgr; /* default icon manager */ struct IconRegion *FirstRegion; /* pointer to icon regions */ struct IconRegion *LastRegion; /* pointer to the last icon region */ - char *IconDirectory; /* icon directory to search */ + const char *IconDirectory; /* icon directory to search */ int SizeStringOffset; /* x offset in size window for drawing */ int SizeStringWidth; /* minimum width of size window */ int BorderWidth; /* border width of twm windows */ diff --git a/src/util.c b/src/util.c index 9e5675a..d539066 100644 --- a/src/util.c +++ b/src/util.c @@ -255,21 +255,21 @@ Zoom(Window wf, Window wt) * * \param name the filename to expand */ -char * -ExpandFilename(char *name) +const char * +ExpandFilename(const char *name) { char *newname; if (name[0] != '~') return name; - newname = malloc (HomeLen + strlen(name) + 2); + newname = malloc(HomeLen + strlen(name) + 2); if (!newname) { - fprintf (stderr, - "%s: unable to allocate %ld bytes to expand filename %s/%s\n", - ProgramName, HomeLen + (unsigned long)strlen(name) + 2, - Home, &name[1]); + fprintf(stderr, + "%s: unable to allocate %ld bytes to expand filename %s/%s\n", + ProgramName, HomeLen + (unsigned long)strlen(name) + 2, + Home, &name[1]); } else { - (void) sprintf (newname, "%s/%s", Home, &name[1]); + (void) sprintf(newname, "%s/%s", Home, &name[1]); } return newname; @@ -341,7 +341,7 @@ FindBitmap (const char *name, unsigned *widthp, unsigned *heightp) * are used. If the bigname is different from name, bigname will need to * be freed. */ - bigname = ExpandFilename (name); + bigname = (char*)ExpandFilename(name); if (!bigname) return None; /* @@ -598,7 +598,7 @@ GetFont(MyFont *font) basename2 = malloc(strlen(font->name) + 3); if (basename2) sprintf(basename2, "%s,*", font->name); - else basename2 = font->name; + else basename2 = (char*)font->name; if( (font->fontset = XCreateFontSet(dpy, basename2, &missing_charset_list_return, &missing_charset_count_return, diff --git a/src/util.h b/src/util.h index 7f4527c..1649395 100644 --- a/src/util.h +++ b/src/util.h @@ -64,7 +64,7 @@ in this Software without prior written authorization from The Open Group. extern void MoveOutline ( Window root, int x, int y, int width, int height, int bw, int th ); extern void Zoom ( Window wf, Window wt ); -extern char * ExpandFilename ( char *name ); +extern const char * ExpandFilename ( const char *name ); extern void GetUnknownIcon ( const char *name ); extern Pixmap FindBitmap ( const char *name, unsigned int *widthp, unsigned int *heightp );