[njs] Fixed conversion of NAN and INF to uint32_t on some platforms.

Dmitry Volyntsev xeioex at nginx.com
Thu Nov 29 15:16:43 UTC 2018


details:   https://hg.nginx.org/njs/rev/cf424d6313ae
branches:  
changeset: 676:cf424d6313ae
user:      Dmitry Volyntsev <xeioex at nginx.com>
date:      Thu Nov 29 18:14:12 2018 +0300
description:
Fixed conversion of NAN and INF to uint32_t on some platforms.

diffstat:

 njs/njs_builtin.c |   2 +-
 njs/njs_number.c  |  11 +++++++++++
 nxt/auto/clang    |  17 +++++++++++++++++
 3 files changed, 29 insertions(+), 1 deletions(-)

diffs (57 lines):

diff -r da67f08d365e -r cf424d6313ae njs/njs_builtin.c
--- a/njs/njs_builtin.c	Wed Nov 28 15:47:05 2018 +0300
+++ b/njs/njs_builtin.c	Thu Nov 29 18:14:12 2018 +0300
@@ -1085,7 +1085,7 @@ njs_dump_value(njs_vm_t *vm, njs_value_t
     value = njs_arg(args, nargs, 1);
     indent = njs_arg(args, nargs, 2);
 
-    n = indent->data.u.number;
+    n = njs_primitive_value_to_integer(indent);
     n = nxt_min(n, 5);
 
     if (njs_vm_value_dump(vm, &str, value, n) != NXT_OK) {
diff -r da67f08d365e -r cf424d6313ae njs/njs_number.c
--- a/njs/njs_number.c	Wed Nov 28 15:47:05 2018 +0300
+++ b/njs/njs_number.c	Thu Nov 29 18:14:12 2018 +0300
@@ -789,6 +789,17 @@ njs_number_to_integer(double num)
 {
     int64_t  i64;
 
+#if (NXT_NAN_TO_UINT_CONVERSION != 0)
+    /*
+     * PPC32: NaN and Inf are converted to 0x8000000080000000
+     * and become non-zero after truncation.
+     */
+
+    if (isnan(num) || isinf(num)) {
+        return 0;
+    }
+#endif
+
     /*
      * ES5.1: integer must be modulo 2^32.
      * 2^53 is the largest integer number which can be stored safely
diff -r da67f08d365e -r cf424d6313ae nxt/auto/clang
--- a/nxt/auto/clang	Wed Nov 28 15:47:05 2018 +0300
+++ b/nxt/auto/clang	Thu Nov 29 18:14:12 2018 +0300
@@ -302,3 +302,20 @@ else
     . ${NXT_AUTO}feature
 
 fi
+
+
+nxt_feature="NAN to uint conversion"
+nxt_feature_name=NXT_NAN_TO_UINT_CONVERSION
+nxt_feature_run=value
+nxt_feature_incs=
+nxt_feature_libs=-lm
+nxt_feature_test="#include <math.h>
+                  #include <stdio.h>
+                  #include <stdint.h>
+
+                  int main(void) {
+                      int64_t  i64 = sqrt(-1);
+                      printf(\"%x\", (uint32_t) i64);
+                      return 0;
+                  }"
+. ${NXT_AUTO}feature


More information about the nginx-devel mailing list