use BLI_strncpy and BLI_snprintf when the size of the string is known.
[blender.git] / source / blender / editors / util / numinput.c
index ccdbe7d..52422d3 100644 (file)
@@ -1,6 +1,4 @@
-/**
- * $Id$
- *
+/*
  * ***** BEGIN GPL LICENSE BLOCK *****
  *
  * This program is free software; you can redistribute it and/or
  * ***** END GPL LICENSE BLOCK *****
  */
 
+/** \file blender/editors/util/numinput.c
+ *  \ingroup edutil
+ */
+
+
 #include <math.h>                      /* fabs */
-#include <stdio.h>                     /* for sprintf          */
+#include <stdio.h>                     /* for size_t */
 
 #include "BLI_utildefines.h"
+#include "BLI_string.h"
 
 #include "WM_types.h"
 
@@ -80,35 +84,35 @@ void outputNumInput(NumInput *n, char *str)
                else
                        inv[0] = 0;
 
-               if( n->val[i] > 1e10 || n->val[i] < -1e10 )
-                       sprintf(&str[j*20], "%s%.4e%c", inv, n->val[i], cur);
+               if( n->val[i] > 1e10f || n->val[i] < -1e10f )
+                       BLI_snprintf(&str[j*20], 20, "%s%.4e%c", inv, n->val[i], cur);
                else
                        switch (n->ctrl[i]) {
                        case 0:
-                               sprintf(&str[j*20], "%sNONE%c", inv, cur);
+                               BLI_snprintf(&str[j*20], 20, "%sNONE%c", inv, cur);
                                break;
                        case 1:
                        case -1:
-                               sprintf(&str[j*20], "%s%.0f%c", inv, n->val[i], cur);
+                               BLI_snprintf(&str[j*20], 20, "%s%.0f%c", inv, n->val[i], cur);
                                break;
                        case 10:
                        case -10:
-                               sprintf(&str[j*20], "%s%.f.%c", inv, n->val[i], cur);
+                               BLI_snprintf(&str[j*20], 20, "%s%.f.%c", inv, n->val[i], cur);
                                break;
                        case 100:
                        case -100:
-                               sprintf(&str[j*20], "%s%.1f%c", inv, n->val[i], cur);
+                               BLI_snprintf(&str[j*20], 20, "%s%.1f%c", inv, n->val[i], cur);
                                break;
                        case 1000:
                        case -1000:
-                               sprintf(&str[j*20], "%s%.2f%c", inv, n->val[i], cur);
+                               BLI_snprintf(&str[j*20], 20, "%s%.2f%c", inv, n->val[i], cur);
                                break;
                        case 10000:
                        case -10000:
-                               sprintf(&str[j*20], "%s%.3f%c", inv, n->val[i], cur);
+                               BLI_snprintf(&str[j*20], 20, "%s%.3f%c", inv, n->val[i], cur);
                                break;
                        default:
-                               sprintf(&str[j*20], "%s%.4e%c", inv, n->val[i], cur);
+                               BLI_snprintf(&str[j*20], 20, "%s%.4e%c", inv, n->val[i], cur);
                        }
        }
 }
@@ -276,7 +280,7 @@ char handleNumInput(NumInput *n, wmEvent *event)
                        if (!n->ctrl[idx])
                                n->ctrl[idx] = 1;
 
-                       if (fabs(n->val[idx]) > 9999999.0f);
+                       if (fabsf(n->val[idx]) > 9999999.0f);
                        else if (n->ctrl[idx] == 1) {
                                n->val[idx] *= 10;
                                n->val[idx] += Val;
@@ -298,7 +302,7 @@ char handleNumInput(NumInput *n, wmEvent *event)
                }
        }
        
-       printf("%f\n", n->val[idx]);
+       // printf("%f\n", n->val[idx]);
 
        /* REDRAW SINCE NUMBERS HAVE CHANGED */
        return 1;