cjson/backport-fix-print-int-without-decimal-places-630.patch
Zhao Mengmeng de2287f574 Sync patches from 24.03 branch
Sync these patches from 24.03 branch:
- Fix-a-null-pointer-crash-in-cJSON_ReplaceItemViaPoin.patch
- backport-Add-test-for-heap-buffer-overflow.patch
- backport-Fix-heap-buffer-overflow.patch
- backport-fix-add-allocate-check-for-replace_item_in_object-67.patch
- backport-fix-print-int-without-decimal-places-630.patch
- backport-Set-free-d-pointers-to-NULL-whenever-they-are-not-re.patch

Signed-off-by: Zhao Mengmeng <zhaomengmeng@kylinos.cn>
2024-06-18 16:38:13 +08:00

27 lines
791 B
Diff

From d321fa9e6e574ff93518f6384865b9af0a4a4afc Mon Sep 17 00:00:00 2001
From: AlexanderVasiljev <48011002+AlexanderVasiljev@users.noreply.github.com>
Date: Wed, 19 Jan 2022 05:30:31 +0300
Subject: [PATCH] fix: print int without decimal places (#630)
---
cJSON.c | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/cJSON.c b/cJSON.c
index 3063f74..c78aac6 100644
--- a/cJSON.c
+++ b/cJSON.c
@@ -562,6 +562,10 @@ static cJSON_bool print_number(const cJSON * const item, printbuffer * const out
{
length = sprintf((char*)number_buffer, "null");
}
+ else if(d == (double)item->valueint)
+ {
+ length = sprintf((char*)number_buffer, "%d", item->valueint);
+ }
else
{
/* Try 15 decimal places of precision to avoid nonsignificant nonzero digits */
--