Constness and global namespace patrol.
[pspp-builds.git] / src / data / data-out.c
index 79c7042446abb453c2c1722b118303805dd5b217..6106fc3011f420f7080252db49c2c14f4c03ad0f 100644 (file)
@@ -25,6 +25,7 @@
 #include <stdlib.h>
 #include <time.h>
 #include "calendar.h"
+#include <libpspp/assertion.h>
 #include <libpspp/message.h>
 #include "format.h"
 #include <libpspp/magic.h>
@@ -36,8 +37,6 @@
 
 #include "gettext.h"
 #define _(msgid) gettext (msgid)
-
-#include <libpspp/debug-print.h>
 \f
 /* Public functions. */
 
@@ -103,12 +102,10 @@ data_out (char *s, const struct fmt_spec *fp, const union value *v)
           break;
 
         case FMT_A:
-          assert (0);
-          abort ();
+          NOT_REACHED ();
 
         case FMT_AHEX:
-          assert (0);
-          abort ();
+          NOT_REACHED ();
 
         case FMT_IB:
           ok = convert_IB (s, fp, number);
@@ -161,8 +158,7 @@ data_out (char *s, const struct fmt_spec *fp, const union value *v)
           break;
 
         default:
-          assert (0);
-          abort ();
+          NOT_REACHED ();
         }
     }
   else 
@@ -181,8 +177,7 @@ data_out (char *s, const struct fmt_spec *fp, const union value *v)
           break;
 
         default:
-          assert (0);
-          abort ();
+          NOT_REACHED ();
         }
     }
 
@@ -353,7 +348,7 @@ convert_F_plus (char *dst, const struct fmt_spec *fp, double number)
 static int
 convert_Z (char *dst, const struct fmt_spec *fp, double number)
 {
-  static int warned = 0;
+  static bool warned = false;
 
   if (!warned)
     {
@@ -397,7 +392,7 @@ convert_Z (char *dst, const struct fmt_spec *fp, double number)
 static int
 convert_A (char *dst, const struct fmt_spec *fp, const char *string)
 {
-  memcpy (dst, string, fp->w);
+  memcpy(dst, string, fp->w);
   return 1;
 }
 
@@ -753,7 +748,7 @@ convert_date (char *dst, const struct fmt_spec *fp, double number)
       }
       break;
     default:
-      assert (0);
+      NOT_REACHED ();
     }
 
   if (buf[0] == 0)
@@ -1065,6 +1060,7 @@ try_F (char *dst, const struct fmt_spec *fp, double number)
                  avoids wasting too much time formatting more
                  decimal places on the first try. */
               int result = format_and_round (dst, number, fp, fp->d + 2);
+
               if (result >= 0)
                 return result;
 
@@ -1145,7 +1141,7 @@ format_and_round (char *dst, double number, const struct fmt_spec *fp,
          digits of the fraction.
          Right-justify the integer part and sign. */
       dst[0] = ' ';
-      memcpy (dst + 1, buf, fp->w);
+      memcpy (dst + 1, buf, fp->w - 1);
       return 1;
     }