Explorar o código

ncd: modules: use ncd_make_uintmax() where appropriate

ambrop7 %!s(int64=13) %!d(string=hai) anos
pai
achega
1ee2f80760
Modificáronse 2 ficheiros con 5 adicións e 11 borrados
  1. 2 6
      ncd/modules/arithmetic.c
  2. 3 5
      ncd/modules/parse.c

+ 2 - 6
ncd/modules/arithmetic.c

@@ -270,13 +270,9 @@ static int number_func_getvar2 (void *vo, NCD_string_id_t name, NCDValMem *mem,
     struct number_instance *o = vo;
     
     if (name == NCD_STRING_EMPTY) {
-        int size = compute_decimal_repr_size(o->value);
-        *out = NCDVal_NewStringUninitialized(mem, size);
+        *out = ncd_make_uintmax(mem, o->value);
         if (NCDVal_IsInvalid(*out)) {
-            ModuleLog(o->i, BLOG_ERROR, "NCDVal_NewString failed");
-        } else {
-            char *data = (char *)NCDVal_StringValue(*out);
-            generate_decimal_repr(o->value, data, size);
+            ModuleLog(o->i, BLOG_ERROR, "ncd_make_uintmax failed");
         }
         return 1;
     }

+ 3 - 5
ncd/modules/parse.c

@@ -56,6 +56,7 @@
 #include <ncd/NCDValParser.h>
 #include <ncd/NCDModule.h>
 #include <ncd/static_strings.h>
+#include <ncd/value_utils.h>
 
 #include <generated/blog_channel_ncd_parse.h>
 
@@ -90,12 +91,9 @@ static int parse_number (NCDModuleInst *i, const char *str, size_t str_len, NCDV
         return 0;
     }
     
-    char buf[25];
-    snprintf(buf, sizeof(buf), "%"PRIuMAX, n);
-    
-    *out = NCDVal_NewString(mem, buf);
+    *out = ncd_make_uintmax(mem, n);
     if (NCDVal_IsInvalid(*out)) {
-        ModuleLog(i, BLOG_ERROR, "NCDVal_NewString failed");
+        ModuleLog(i, BLOG_ERROR, "ncd_make_uintmax failed");
         return 0;
     }