You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by ma...@apache.org on 2016/05/17 18:58:00 UTC

[4/8] incubator-mynewt-core git commit: Fix json encoding

Fix json encoding

- Changing atoi to strtoull and strtoll as atoi return only 32 bit
  values. strtoll and strtoull return 64bit values which we encode our
inetegers as.
- Changing a few other places where json encoding should use 64 bit
  values instead of 32 bit.


Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/commit/ed16b3f2
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/ed16b3f2
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/ed16b3f2

Branch: refs/heads/develop
Commit: ed16b3f2e21809b68f45b10777cfb1331be0f697
Parents: 57e945d
Author: Vipul Rahane <vi...@runtime.io>
Authored: Mon Apr 25 17:33:21 2016 -0700
Committer: Vipul Rahane <vi...@runtime.io>
Committed: Mon May 16 14:16:53 2016 -0700

----------------------------------------------------------------------
 libs/json/include/json/json.h |  8 ++++----
 libs/json/src/json_decode.c   | 20 +++++++++++---------
 2 files changed, 15 insertions(+), 13 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/ed16b3f2/libs/json/include/json/json.h
----------------------------------------------------------------------
diff --git a/libs/json/include/json/json.h b/libs/json/include/json/json.h
index 1b97d1b..8460126 100644
--- a/libs/json/include/json/json.h
+++ b/libs/json/include/json/json.h
@@ -128,8 +128,8 @@ typedef enum {
 } json_type;
 
 struct json_enum_t {
-    char        *name;
-    int                value;
+    char *name;
+    long long int value;
 };
 
 struct json_array_t {
@@ -146,10 +146,10 @@ struct json_array_t {
             int storelen;
         } strings;
         struct {
-            int *store;
+            long long int *store;
         } integers;
         struct {
-            unsigned int *store;
+            long long unsigned int *store;
         } uintegers;
         struct {
             double *store;

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/ed16b3f2/libs/json/src/json_decode.c
----------------------------------------------------------------------
diff --git a/libs/json/src/json_decode.c b/libs/json/src/json_decode.c
index 2dcde6f..0d81c0d 100644
--- a/libs/json/src/json_decode.c
+++ b/libs/json/src/json_decode.c
@@ -152,10 +152,10 @@ json_internal_read_object(struct json_buffer *jb, const struct json_attr_t *attr
             if (lptr != NULL) {
                 switch (cursor->type) {
                 case t_integer:
-                    memcpy(lptr, &cursor->dflt.integer, sizeof(int));
+                    memcpy(lptr, &cursor->dflt.integer, sizeof(long long int));
                     break;
                 case t_uinteger:
-                    memcpy(lptr, &cursor->dflt.uinteger, sizeof(unsigned int));
+                    memcpy(lptr, &cursor->dflt.uinteger, sizeof(long long unsigned int));
                     break;
                 case t_real:
                     memcpy(lptr, &cursor->dflt.real, sizeof(double));
@@ -396,19 +396,21 @@ json_internal_read_object(struct json_buffer *jb, const struct json_attr_t *attr
                 }
                 return JSON_ERR_BADENUM;
               foundit:
-                (void)snprintf(valbuf, sizeof(valbuf), "%d", mp->value);
+                (void)snprintf(valbuf, sizeof(valbuf), "%lld", mp->value);
             }
             lptr = json_target_address(cursor, parent, offset);
             if (lptr != NULL) {
                 switch (cursor->type) {
                 case t_integer: {
-                        int tmp = atoi(valbuf);
-                        memcpy(lptr, &tmp, sizeof(int));
+                        long long int tmp =
+                            (long long int)strtoll(valbuf, NULL, 10);
+                        memcpy(lptr, &tmp, sizeof(long long int));
                     }
                     break;
                 case t_uinteger: {
-                        unsigned int tmp = (unsigned int)atoi(valbuf);
-                        memcpy(lptr, &tmp, sizeof(unsigned int));
+                        long long unsigned int tmp =
+                            (long long unsigned int)strtoull(valbuf, NULL, 10);
+                        memcpy(lptr, &tmp, sizeof(long long unsigned int));
                     }
                     break;
                 case t_real: {
@@ -548,7 +550,7 @@ json_read_array(struct json_buffer *jb, const struct json_array_t *arr)
             n = jb->jb_readn(jb, valbuf, sizeof(valbuf)-1);
             valbuf[n] = '\0';
 
-            arr->arr.integers.store[offset] = (int)strtol(valbuf, &ep, 0);
+            arr->arr.integers.store[offset] = (long long int)strtoll(valbuf, &ep, 0);
             if (ep == valbuf) {
                 return JSON_ERR_BADNUM;
             } else {
@@ -562,7 +564,7 @@ json_read_array(struct json_buffer *jb, const struct json_array_t *arr)
             n = jb->jb_readn(jb, valbuf, sizeof(valbuf)-1);
             valbuf[n] = '\0';
 
-            arr->arr.uintegers.store[offset] = (unsigned int)strtoul(valbuf, &ep, 0);
+            arr->arr.uintegers.store[offset] = (long long unsigned int)strtoull(valbuf, &ep, 0);
             if (ep == valbuf) {
                 return JSON_ERR_BADNUM;
             } else {