[m-rev.] diff: avoid more C compiler warnings in the library and compiler directories

Julien Fischer jfischer at opturion.com
Mon Mar 31 02:04:00 AEDT 2014


Branches: 14.01, master

-----------------------

Avoid more C compiler warnings in the library and compiler directories.

library/io.m:
 	Add casts where appropriate to avoid warnings.

 	Return a dummy time value in io.file_modification_time_2/6 when the
 	call to stat() fails.  (This is safe since the caller will never
 	examine this value if the call to stat() fails.)  Doing so avoids
 	a warning about the time value not being initialized in some branches.

library/string.m:
 	Delete unused local variables in foreign_procs.

library/time.m:
compiler/timestamp.m:
 	Cast assignments to the fields of the tm structure to ints.

compiler/md4.m:
 	Avoid a warning about comparing integers of different signedness.

compiler/process_util.m:
 	Add casts where appropriate to avoid warnings.

Julien.

diff --git a/compiler/md4.m b/compiler/md4.m
index 1e539a5..c9b28ee 100644
--- a/compiler/md4.m
+++ b/compiler/md4.m
@@ -239,7 +239,7 @@ static void mdfour_result(const struct mdfour *m, unsigned char *out)
      unsigned char sum[16];
      char hexbuf[sizeof(sum) * 2 + 1];
      char *p;
-    int i;
+    size_t i;

      mdfour_begin(&md);
      mdfour_update(&md, (const unsigned char *)In, strlen(In));
diff --git a/compiler/process_util.m b/compiler/process_util.m
index 0af6dc5..a45b212 100644
--- a/compiler/process_util.m
+++ b/compiler/process_util.m
@@ -297,7 +297,7 @@ raise_signal(_::in, IO::di, IO::uo).
      raise_signal(Signal::in, _IO0::di, _IO::uo),
      [will_not_call_mercury, promise_pure, tabled_for_io],
  "
-    raise(Signal);
+    raise((int)Signal);
  ").

  :- pragma foreign_proc("C",
@@ -305,7 +305,7 @@ raise_signal(_::in, IO::di, IO::uo).
      [will_not_call_mercury, promise_pure, tabled_for_io],
  "
  #ifdef MR_HAVE_KILL
-    kill(Pid, Signal);
+    kill((pid_t)Pid, (int)Signal);
  #endif
  ").

@@ -393,7 +393,7 @@ start_in_forked_process_2(_, _, !IO) :-
          MR_Integer exit_status;

          MC_call_child_process_io_pred(Pred, &exit_status);
-        exit(exit_status);
+        exit((int)exit_status);
      } else {                                /* parent */
      }

@@ -451,7 +451,7 @@ call_child_process_io_pred(P, Status, !IO) :-
  #endif

          while (1) {
-            wait_status = waitpid(Pid, &child_status, 0);
+            wait_status = waitpid((pid_t)Pid, &child_status, 0);
              if (wait_status != -1) {
                  WaitedPid = wait_status;
                  Status = child_status;
@@ -466,7 +466,7 @@ call_child_process_io_pred(P, Status, !IO) :-
                      ** Linux).
                      */
                      if (Pid != -1) {
-                        kill(Pid, SIGTERM);
+                        kill((pid_t)Pid, SIGTERM);
                      }
                      break;
                  }
diff --git a/compiler/timestamp.m b/compiler/timestamp.m
index 287a992..458fb70 100644
--- a/compiler/timestamp.m
+++ b/compiler/timestamp.m
@@ -96,15 +96,15 @@ gmtime_to_timestamp(tm(Year, Month, MD, Hrs, Min, Sec, YD, WD, DST)) =
      int size;
      struct tm t;

-    t.tm_sec = Sec;
-    t.tm_min = Min;
-    t.tm_hour = Hrs;
-    t.tm_mon = Mnt;
-    t.tm_year = Yr;
-    t.tm_wday = WD;
-    t.tm_mday = MD;
-    t.tm_yday = YD;
-    t.tm_isdst = N;
+    t.tm_sec = (int) Sec;
+    t.tm_min = (int) Min;
+    t.tm_hour = (int) Hrs;
+    t.tm_mon = (int) Mnt;
+    t.tm_year = (int) Yr;
+    t.tm_wday = (int) WD;
+    t.tm_mday = (int) MD;
+    t.tm_yday = (int) YD;
+    t.tm_isdst = (int) N;

      size = sizeof ""yyyy-mm-dd hh:mm:ss"";
      MR_allocate_aligned_string_msg(Result, size - 1, MR_ALLOC_ID);
diff --git a/library/io.m b/library/io.m
index 0a0283c..501f1e7 100644
--- a/library/io.m
+++ b/library/io.m
@@ -2188,7 +2188,7 @@ io.read_line_as_string(input_stream(Stream), Result, !IO) :-
              Res = -2;
              break;
          }
-        read_buffer[i++] = char_code;
+        read_buffer[i++] = (char) char_code;
          MR_assert(i <= read_buf_size);
          if (i == read_buf_size) {
              /* Grow the read buffer */
@@ -2851,6 +2851,7 @@ io.file_modification_time(File, Result, !IO) :-
          ML_maybe_make_err_msg(MR_TRUE, errno, ""stat() failed: "",
              MR_ALLOC_ID, MR_TRUE, Msg);
          Status = 0;
+        Time = 0;   /* Dummy value -- will not be used. */
      }
  #else
      Status = 0;
@@ -7548,7 +7549,7 @@ io.read_char_code(input_stream(Stream), CharCode, !IO) :-
              nbytes = 0;
          }
          if (nbytes > 0) {
-            buf[0] = uc;
+            buf[0] = (char) uc;
              for (i = 1; i < nbytes; i++) {
                  uc = mercury_get_byte(Stream);
                  buf[i] = uc;
@@ -9610,7 +9611,7 @@ io.close_binary_output(binary_output_stream(Stream), !IO) :-
      [will_not_call_mercury, promise_pure, tabled_for_io,
          does_not_affect_liveness, no_sharing],
  "
-    mercury_exit_status = ExitStatus;
+    mercury_exit_status = (int) ExitStatus;
  ").

  :- pragma foreign_decl("C", "
diff --git a/library/string.m b/library/string.m
index f8b3faa..0a27063 100644
--- a/library/string.m
+++ b/library/string.m
@@ -2327,7 +2327,6 @@ string.append_list(Lists, string.append_list(Lists)).
          does_not_affect_liveness, may_not_duplicate, no_sharing],
  "{
      MR_Word list = Strs;
-    MR_Word tmp;
      size_t  len;

      /* Determine the total length of all strings */
@@ -2405,7 +2404,6 @@ string.append_list(Strs::in) = (Str::uo) :-
          does_not_affect_liveness, may_not_duplicate, no_sharing],
  "{
      MR_Word list;
-    MR_Word tmp;
      size_t  len;
      size_t  sep_len;
      MR_bool add_sep;
@@ -4847,7 +4845,6 @@ string.set_char(Char, Index, !Str) :-
              size_t oldwidth = MR_utf8_width(oldc);
              size_t newwidth = MR_utf8_width(Ch);
              size_t newlen;
-            size_t tailofs;

              newlen = len - oldwidth + newwidth;
              MR_allocate_aligned_string_msg(Str, newlen, MR_ALLOC_ID);
@@ -5480,7 +5477,6 @@ strchars(I, End, Str) = Chars :-
  "{
      MR_Integer  len;
      MR_Integer  Count;
-    MR_Word     tmp;

      if (Start < 0) Start = 0;
      if (End <= Start) {
@@ -5650,7 +5646,6 @@ string.unsafe_substring(Str, Start, Count, SubString) :-
          does_not_affect_liveness, may_not_duplicate],
  "{
      MR_Integer  len;
-    MR_Word     tmp;

      if (Count <= 0) {
          MR_make_aligned_string(Left, """");
diff --git a/library/time.m b/library/time.m
index 8de500c..e050668 100644
--- a/library/time.m
+++ b/library/time.m
@@ -836,15 +836,15 @@ time.mktime(TM) = time_t(Time) :-
   "{
      struct tm t;

-    t.tm_sec = Sec;
-    t.tm_min = Min;
-    t.tm_hour = Hrs;
-    t.tm_mon = Mnt;
-    t.tm_year = Yr;
-    t.tm_wday = WD;
-    t.tm_mday = MD;
-    t.tm_yday = YD;
-    t.tm_isdst = N;
+    t.tm_sec = (int) Sec;
+    t.tm_min = (int) Min;
+    t.tm_hour = (int) Hrs;
+    t.tm_mon = (int) Mnt;
+    t.tm_year = (int) Yr;
+    t.tm_wday = (int) WD;
+    t.tm_mday = (int) MD;
+    t.tm_yday = (int) YD;
+    t.tm_isdst = (int) N;

      Time = mktime(&t);
  }").



More information about the reviews mailing list