From 8df32cea3359cb30120795da6020b3b73da01d38 Mon Sep 17 00:00:00 2001 From: Amos Bird Date: Sat, 15 May 2021 10:51:07 +0800 Subject: [PATCH] Return err when alloc failure (#1567) --- src/arm64/implementation.cpp | 8 +++++--- src/fallback/implementation.cpp | 8 +++++--- src/haswell/implementation.cpp | 6 ++++-- src/ppc64/implementation.cpp | 8 +++++--- src/westmere/implementation.cpp | 8 +++++--- 5 files changed, 24 insertions(+), 14 deletions(-) diff --git a/src/arm64/implementation.cpp b/src/arm64/implementation.cpp index 7a1929d7b..27c1167be 100644 --- a/src/arm64/implementation.cpp +++ b/src/arm64/implementation.cpp @@ -10,12 +10,14 @@ simdjson_warn_unused error_code implementation::create_dom_parser_implementation ) const noexcept { dst.reset( new (std::nothrow) dom_parser_implementation() ); if (!dst) { return MEMALLOC; } - dst->set_capacity(capacity); - dst->set_max_depth(max_depth); + if (auto err = dst->set_capacity(capacity)) + return err; + if (auto err = dst->set_max_depth(max_depth)) + return err; return SUCCESS; } } // namespace SIMDJSON_IMPLEMENTATION } // namespace simdjson -#include "simdjson/arm64/end.h" \ No newline at end of file +#include "simdjson/arm64/end.h" diff --git a/src/fallback/implementation.cpp b/src/fallback/implementation.cpp index 1f6c1643c..a794ae5e6 100644 --- a/src/fallback/implementation.cpp +++ b/src/fallback/implementation.cpp @@ -10,12 +10,14 @@ simdjson_warn_unused error_code implementation::create_dom_parser_implementation ) const noexcept { dst.reset( new (std::nothrow) dom_parser_implementation() ); if (!dst) { return MEMALLOC; } - dst->set_capacity(capacity); - dst->set_max_depth(max_depth); + if (auto err = dst->set_capacity(capacity)) + return err; + if (auto err = dst->set_max_depth(max_depth)) + return err; return SUCCESS; } } // namespace SIMDJSON_IMPLEMENTATION } // namespace simdjson -#include "simdjson/fallback/end.h" \ No newline at end of file +#include "simdjson/fallback/end.h" diff --git a/src/haswell/implementation.cpp b/src/haswell/implementation.cpp index d41b25381..31ebb5b22 100644 --- a/src/haswell/implementation.cpp +++ b/src/haswell/implementation.cpp @@ -10,8 +10,10 @@ simdjson_warn_unused error_code implementation::create_dom_parser_implementation ) const noexcept { dst.reset( new (std::nothrow) dom_parser_implementation() ); if (!dst) { return MEMALLOC; } - dst->set_capacity(capacity); - dst->set_max_depth(max_depth); + if (auto err = dst->set_capacity(capacity)) + return err; + if (auto err = dst->set_max_depth(max_depth)) + return err; return SUCCESS; } diff --git a/src/ppc64/implementation.cpp b/src/ppc64/implementation.cpp index 75a0d88e3..2c64fa09e 100644 --- a/src/ppc64/implementation.cpp +++ b/src/ppc64/implementation.cpp @@ -10,12 +10,14 @@ simdjson_warn_unused error_code implementation::create_dom_parser_implementation ) const noexcept { dst.reset( new (std::nothrow) dom_parser_implementation() ); if (!dst) { return MEMALLOC; } - dst->set_capacity(capacity); - dst->set_max_depth(max_depth); + if (auto err = dst->set_capacity(capacity)) + return err; + if (auto err = dst->set_max_depth(max_depth)) + return err; return SUCCESS; } } // namespace SIMDJSON_IMPLEMENTATION } // namespace simdjson -#include "simdjson/ppc64/end.h" \ No newline at end of file +#include "simdjson/ppc64/end.h" diff --git a/src/westmere/implementation.cpp b/src/westmere/implementation.cpp index 46f0a9a04..d448556a5 100644 --- a/src/westmere/implementation.cpp +++ b/src/westmere/implementation.cpp @@ -10,12 +10,14 @@ simdjson_warn_unused error_code implementation::create_dom_parser_implementation ) const noexcept { dst.reset( new (std::nothrow) dom_parser_implementation() ); if (!dst) { return MEMALLOC; } - dst->set_capacity(capacity); - dst->set_max_depth(max_depth); + if (auto err = dst->set_capacity(capacity)) + return err; + if (auto err = dst->set_max_depth(max_depth)) + return err; return SUCCESS; } } // namespace SIMDJSON_IMPLEMENTATION } // namespace simdjson -#include "simdjson/westmere/end.h" \ No newline at end of file +#include "simdjson/westmere/end.h"