xmahjongg (3.7-3) 03-compiler-warnings.patch

Summary

 configure         |    4 +++-
 liblcdf/string.cc |    2 +-
 src/game.cc       |    9 ++++++---
 src/main.cc       |    4 ++--
 4 files changed, 12 insertions(+), 7 deletions(-)

    
download this patch

Patch contents

Make the configure script produce the same result with or without -Werror.
Fix a couple of const char * warnings.
Teach the the layout parser about read errors.

--- a/configure
+++ b/configure
@@ -6193,7 +6193,8 @@
 int
 main ()
 {
-gettimeofday((void *)0, (void *)0);
+struct timeval tv;
+gettimeofday(&tv, (void *)0);
   ;
   return 0;
 }
@@ -8267,6 +8268,7 @@
 
   int a;
   int *b = new(&a) int;
+  a = *b;
   return 0;
 
   ;
--- a/liblcdf/string.cc
+++ b/liblcdf/string.cc
@@ -37,7 +37,7 @@
 
 inline
 String::Memo::Memo()
-    : _refcount(0), _capacity(0), _dirty(0), _real_data("")
+    : _refcount(0), _capacity(0), _dirty(0), _real_data(new char[1])
 {
 }
 
--- a/src/main.cc
+++ b/src/main.cc
@@ -230,7 +230,7 @@
 
 
 Button *
-new_button(Panel *panel, char *name)
+new_button(Panel *panel, const char *name)
 {
   char buf[100];
   Button *but = new Button(panel);
@@ -708,7 +708,7 @@
     XStringListToTextProperty(woog, 1, &window_name_prop);
     XStringListToTextProperty(woog, 1, &icon_name_prop);
     class_hint.res_name = (char *)(x_name ? x_name : program_name);
-    class_hint.res_class = "XMahjongg";
+    class_hint.res_class = (char *)"XMahjongg";
 
     XResizeWindow(display, window, size_hint->width, size_hint->height);
     XSetWMProperties(display, window, &window_name_prop, &icon_name_prop,
--- a/src/game.cc
+++ b/src/game.cc
@@ -497,7 +497,8 @@
   char buffer[BUFSIZ];
   while (!feof(f)) {
     buffer[0] = 0;
-    fgets(buffer, BUFSIZ, f);
+    if (fgets(buffer, BUFSIZ, f) == NULL)
+      return false;
     int r, c, l;
     if (sscanf(buffer, " %d %d %d", &r, &c, &l) == 3)
       if (!place_tile(r+2, c+2, l))
@@ -513,7 +514,8 @@
 
   // check for `kmahjongg-layout'
   buf[0] = 0;
-  fgets(buf, BUFSIZ, f);
+  if (fgets(buf, BUFSIZ, f) == NULL)
+    return false;
   if (memcmp(buf, "kmahjongg-layout-v1", 19) != 0) {
     fprintf(stderr, "not a kmahjongg layout file\n");
     return false;
@@ -524,7 +526,8 @@
   while (!feof(f) && l < TILE_LEVS - 1) {
     for (int r = 0; r < 16 && !feof(f); r++) {
       buf[0] = 0;
-      fgets(buf, BUFSIZ, f);
+      if (fgets(buf, BUFSIZ, f) == NULL)
+	return false;
       for (int c = 0; c < TILE_COLS - 3 && buf[c] && !isspace(buf[c]); c++)
 	if (buf[c] == '1') {
 	  if (!place_tile(r + 2, c + 2, l))