summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.gitignore1
-rw-r--r--Makefile.am32
-rw-r--r--config.h.in2
-rw-r--r--configure.ac (renamed from configure.in)35
-rw-r--r--json.pc.in11
-rw-r--r--json_object.c33
-rw-r--r--json_tokener.c2
7 files changed, 64 insertions, 52 deletions
diff --git a/.gitignore b/.gitignore
index 4644691..d3e748e 100644
--- a/.gitignore
+++ b/.gitignore
@@ -7,6 +7,7 @@
/autom4te.cache
/config.guess
/json_config.h
+/compile
/config.h
/config.log
/config.status
diff --git a/Makefile.am b/Makefile.am
index 73e8116..24b9bdf 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -4,15 +4,9 @@ EXTRA_DIST = README.html README-WIN32.html config.h.win32 doc json-c.vcproj
SUBDIRS = . tests
lib_LTLIBRARIES = libjson-c.la
-if ENABLE_OLDNAME_COMPAT
-lib_LTLIBRARIES+=libjson.la
-endif
pkgconfigdir = $(libdir)/pkgconfig
pkgconfig_DATA = json-c.pc
-if ENABLE_OLDNAME_COMPAT
-pkgconfig_DATA += json.pc
-endif
libjson_cincludedir = $(includedir)/json-c
libjson_cinclude_HEADERS = \
@@ -36,15 +30,7 @@ libjson_cinclude_HEADERS = \
#libjsonx_include_HEADERS = \
# json_config.h
-libjson_c_la_LDFLAGS = -version-info 2:0:0 -no-undefined
-
-if ENABLE_OLDNAME_COMPAT
-libjson_la_LDFLAGS = -version-info 1:0:1 -no-undefined -ljson-c
-
-# Temporary libjson library. This will be removed after one release.
-libjson_la_LIBADD = -ljson-c
-endif
-
+libjson_c_la_LDFLAGS = -version-info 2:0:0 -no-undefined @JSON_BSYMBOLIC_LDFLAGS@
libjson_c_la_SOURCES = \
arraylist.c \
@@ -61,26 +47,14 @@ libjson_c_la_SOURCES = \
distclean-local:
-rm -rf $(testsubdir)
-rm -rf config.h.in~ Makefile.in aclocal.m4 autom4te.cache/ config.guess config.sub depcomp install-sh ltmain.sh missing
+ -rm -f INSTALL test-driver tests/Makefile.in compile
maintainer-clean-local:
-rm -rf configure
-if ENABLE_OLDNAME_COMPAT
-# Remove old headers and create a compatibility link
-install-data-hook:
- if test -d "$(DESTDIR)@includedir@/json" ; then \
- (cd "$(DESTDIR)@includedir@/json" && \
- rm -f $(libjson_cinclude_HEADERS)) ; \
- rmdir "$(DESTDIR)@includedir@/json" ; \
- fi
- test \! -e "$(DESTDIR)@includedir@/json" || rm "$(DESTDIR)@includedir@/json"
- $(LN_S) json-c "$(DESTDIR)@includedir@/json"
-
uninstall-local:
- rm -f "$(DESTDIR)@includedir@/json"
rm -rf "$(DESTDIR)@includedir@/json-c"
-
-endif
+ rm -f "$(DESTDIR)@includedir@/json"
ANDROID_CFLAGS = -I$(top_srcdir) -DHAVE_CONFIG_H
diff --git a/config.h.in b/config.h.in
index a912bb0..e59a5a3 100644
--- a/config.h.in
+++ b/config.h.in
@@ -1,4 +1,4 @@
-/* config.h.in. Generated from configure.in by autoheader. */
+/* config.h.in. Generated from configure.ac by autoheader. */
/* Define if .gnu.warning accepts long strings. */
#undef HAS_GNU_WARNING_LONG
diff --git a/configure.in b/configure.ac
index 64f9cbe..878caea 100644
--- a/configure.in
+++ b/configure.ac
@@ -7,14 +7,6 @@ AM_INIT_AUTOMAKE(AC_PACKAGE_NAME, AC_PACKAGE_VERSION)
AC_PROG_MAKE_SET
-AC_ARG_ENABLE(oldname-compat,
- AS_HELP_STRING([--disable-oldname-compat],
- [Don't include the old libjson.so library and include/json directory.]),
-[],
-[enable_oldname_compat=yes]
-)
-AM_CONDITIONAL(ENABLE_OLDNAME_COMPAT, [test "x${enable_oldname_compat}" != "xno"])
-
# Checks for programs.
# Checks for libraries.
@@ -57,9 +49,34 @@ AC_LANG_POP([C])
AM_PROG_LIBTOOL
+# Check for the -Bsymbolic-functions linker flag
+AC_ARG_ENABLE([Bsymbolic],
+ [AS_HELP_STRING([--disable-Bsymbolic], [Avoid linking with -Bsymbolic-function])],
+ [],
+ [enable_Bsymbolic=check])
+
+AS_IF([test "x$enable_Bsymbolic" = "xcheck"],
+ [
+ saved_LDFLAGS="${LDFLAGS}"
+ AC_MSG_CHECKING([for -Bsymbolic-functions linker flag])
+ LDFLAGS=-Wl,-Bsymbolic-functions
+ AC_TRY_LINK([], [int main (void) { return 0; }],
+ [
+ AC_MSG_RESULT([yes])
+ enable_Bsymbolic=yes
+ ],
+ [
+ AC_MSG_RESULT([no])
+ enable_Bsymbolic=no
+ ])
+ LDFLAGS="${saved_LDFLAGS}"
+ ])
+
+AS_IF([test "x$enable_Bsymbolic" = "xyes"], [JSON_BSYMBOLIC_LDFLAGS=-Wl[,]-Bsymbolic-functions])
+AC_SUBST(JSON_BSYMBOLIC_LDFLAGS)
+
AC_CONFIG_FILES([
Makefile
-json.pc
json-c.pc
tests/Makefile
json-c-uninstalled.pc
diff --git a/json.pc.in b/json.pc.in
deleted file mode 100644
index 80e75d1..0000000
--- a/json.pc.in
+++ /dev/null
@@ -1,11 +0,0 @@
-prefix=@prefix@
-exec_prefix=@exec_prefix@
-libdir=@libdir@
-includedir=@includedir@
-
-Name: json-c
-Description: JSON implementation in C, compat shim. Use json-c instead.
-Version: @VERSION@
-Requires: json-c
-Libs:
-Cflags:
diff --git a/json_object.c b/json_object.c
index faf6193..377ab59 100644
--- a/json_object.c
+++ b/json_object.c
@@ -17,6 +17,7 @@
#include <stddef.h>
#include <string.h>
#include <math.h>
+#include <errno.h>
#include "debug.h"
#include "printbuf.h"
@@ -636,6 +637,7 @@ void json_object_free_userdata(struct json_object *jso, void *userdata)
double json_object_get_double(struct json_object *jso)
{
double cdouble;
+ char *errPtr = NULL;
if(!jso) return 0.0;
switch(jso->o_type) {
@@ -646,7 +648,36 @@ double json_object_get_double(struct json_object *jso)
case json_type_boolean:
return jso->o.c_boolean;
case json_type_string:
- if(sscanf(jso->o.c_string.str, "%lf", &cdouble) == 1) return cdouble;
+ errno = 0;
+ cdouble = strtod(jso->o.c_string.str,&errPtr);
+
+ /* if conversion stopped at the first character, return 0.0 */
+ if (errPtr == jso->o.c_string.str)
+ return 0.0;
+
+ /*
+ * Check that the conversion terminated on something sensible
+ *
+ * For example, { "pay" : 123AB } would parse as 123.
+ */
+ if (*errPtr != '\0')
+ return 0.0;
+
+ /*
+ * If strtod encounters a string which would exceed the
+ * capacity of a double, it returns +/- HUGE_VAL and sets
+ * errno to ERANGE. But +/- HUGE_VAL is also a valid result
+ * from a conversion, so we need to check errno.
+ *
+ * Underflow also sets errno to ERANGE, but it returns 0 in
+ * that case, which is what we will return anyway.
+ *
+ * See CERT guideline ERR30-C
+ */
+ if ((HUGE_VAL == cdouble || -HUGE_VAL == cdouble) &&
+ (ERANGE == errno))
+ cdouble = 0.0;
+ return cdouble;
default:
return 0.0;
}
diff --git a/json_tokener.c b/json_tokener.c
index 7c59603..74fd27a 100644
--- a/json_tokener.c
+++ b/json_tokener.c
@@ -74,7 +74,7 @@ const char* json_tokener_errors[] = {
const char *json_tokener_error_desc(enum json_tokener_error jerr)
{
int jerr_int = (int)jerr;
- if (jerr_int < 0 || jerr_int > (int)(sizeof(json_tokener_errors) / sizeof(json_tokener_errors[0])))
+ if (jerr_int < 0 || jerr_int >= (int)(sizeof(json_tokener_errors) / sizeof(json_tokener_errors[0])))
return "Unknown error, invalid json_tokener_error value passed to json_tokener_error_desc()";
return json_tokener_errors[jerr];
}