1 | /* |
2 | * SPDX-License-Identifier: Apache-2.0 |
3 | */ |
4 | |
5 | // ATTENTION: The code in this file is highly EXPERIMENTAL. |
6 | // Adventurous users should note that the APIs will probably change. |
7 | |
8 | #include "onnx/common/assertions.h" |
9 | #include <cstdarg> |
10 | #include <cstdio> |
11 | #include "onnx/common/common.h" |
12 | |
13 | namespace ONNX_NAMESPACE { |
14 | |
15 | std::string barf(const char* fmt, ...) { |
16 | char msg[2048]; |
17 | va_list args; |
18 | |
19 | va_start(args, fmt); |
20 | // Although vsnprintf might have vulnerability issue while using format string with overflowed length, |
21 | // it should be safe here to use fixed length for buffer "msg". No further checking is needed. |
22 | vsnprintf(msg, 2048, fmt, args); |
23 | va_end(args); |
24 | |
25 | return std::string(msg); |
26 | } |
27 | |
28 | void throw_assert_error(std::string& msg) { |
29 | ONNX_THROW_EX(assert_error(msg)); |
30 | } |
31 | |
32 | void throw_tensor_error(std::string& msg) { |
33 | ONNX_THROW_EX(tensor_error(msg)); |
34 | } |
35 | |
36 | } // namespace ONNX_NAMESPACE |
37 | |