]> git.ipfire.org Git - thirdparty/tvheadend.git/commitdiff
Replace long by int64_t in json parser, fixes #5844 (#1349)
authorFlole998 <Flole998@users.noreply.github.com>
Mon, 6 Jul 2020 15:05:05 +0000 (17:05 +0200)
committerGitHub <noreply@github.com>
Mon, 6 Jul 2020 15:05:05 +0000 (17:05 +0200)
src/htsmsg_json.c
src/misc/json.c
src/misc/json.h

index e38286f8d8ca3e38200f1af5820917907d86ede3..28f6c585ee29fa1a6ccc25975af1628e6902f43d 100644 (file)
@@ -22,6 +22,7 @@
 #include <unistd.h>
 #include <stdlib.h>
 #include <string.h>
+#include <stdint.h>
 
 #include "htsmsg_json.h"
 #include "htsbuf.h"
@@ -166,7 +167,7 @@ add_string(void *opaque, void *parent, const char *name,  char *str)
 }
 
 static void 
-add_long(void *opaque, void *parent, const char *name, long v)
+add_s64(void *opaque, void *parent, const char *name, int64_t v)
 {
   htsmsg_add_s64(parent, name, v);
 }
@@ -197,7 +198,7 @@ static const json_deserializer_t json_to_htsmsg = {
   .jd_destroy_obj     = destroy_obj,
   .jd_add_obj         = add_obj,
   .jd_add_string      = add_string,
-  .jd_add_long        = add_long,
+  .jd_add_s64         = add_s64,
   .jd_add_double      = add_double,
   .jd_add_bool        = add_bool,
   .jd_add_null        = add_null,
index 08f8a74da9e97a8482ec23fd279e1c7849e8143e..a1ee74486b1a5eb80bb2e379c55f5114cba671fe 100644 (file)
@@ -20,6 +20,7 @@
 #include <string.h>
 #include <limits.h>
 #include <stdio.h>
+#include <stdint.h>
 
 #include "json.h"
 #include "dbl.h"
@@ -303,7 +304,7 @@ json_parse_double(const char *s, double *dp)
  *
  */
 static char *
-json_parse_integer(const char *s, long *lp)
+json_parse_integer(const char *s, int64_t *lp)
 {
   char *ep;
   while(*s > 0 && *s < 33)
@@ -319,8 +320,8 @@ json_parse_integer(const char *s, long *lp)
   if(s2[0] == '.' || s2[0] == 'e' || s2[0] == 'E')
     return NULL; // Is floating point
 
-  long v = strtol(s, &ep, 10);
-  if(v == LONG_MIN || v == LONG_MAX)
+  int64_t v = strtoll(s, &ep, 10);
+  if(v == INT64_MIN || v == INT64_MAX)
     return NULL;
 
   if(ep == s)
@@ -341,7 +342,7 @@ json_parse_value(const char *s, void *parent, const char *name,
   const char *s2;
   char *str;
   double d = 0;
-  long l = 0;
+  int64_t s64 = 0;
   void *c;
 
   if((c = json_parse_map(s, &s2, jd, opaque, failp, failmsg)) == NULL)
@@ -368,8 +369,8 @@ json_parse_value(const char *s, void *parent, const char *name,
     return s2;
   }
 
-  if((s2 = json_parse_integer(s, &l)) != NULL) {
-    jd->jd_add_long(opaque, parent, name, l);
+  if((s2 = json_parse_integer(s, &s64)) != NULL) {
+    jd->jd_add_s64(opaque, parent, name, s64);
     return s2;
   } else if((s2 = json_parse_double(s, &d)) != NULL) {
     jd->jd_add_double(opaque, parent, name, d);
index 8fc1bf26e9a3ebba04cda88ad01379931849e300..f9643699186e5a9a16c0bcce0c3808c8a209a26b 100644 (file)
@@ -1,4 +1,5 @@
 #pragma once
+#include <stdint.h>
 
 typedef struct json_deserializer {
   void *(*jd_create_map)(void *jd_opaque);
@@ -13,8 +14,8 @@ typedef struct json_deserializer {
   void (*jd_add_string)(void *jd_opaque, void *parent,
                        const char *name, char *str);
 
-  void (*jd_add_long)(void *jd_opaque, void *parent,
-                     const char *name, long v);
+  void (*jd_add_s64)(void *jd_opaque, void *parent,
+                     const char *name, int64_t v);
 
   void (*jd_add_double)(void *jd_opaque, void *parent,
                        const char *name, double d);