From d6f223dc776be94b01472b576646cf834ed0c50c Mon Sep 17 00:00:00 2001 From: Ramakrishna Prabhu Date: Thu, 9 Apr 2026 10:52:15 -0500 Subject: [PATCH] Fix double va_start undefined behavior in error handling functions Remove duplicate va_start() calls in cuopt_expects(), mps_parser_expects(), and mps_parser_expects_fatal(). Calling va_start() twice on the same va_list without an intervening va_end() is undefined behavior per the C standard and can corrupt the stack or produce garbage error messages. Co-Authored-By: Claude Opus 4.6 (1M context) --- cpp/include/cuopt/error.hpp | 2 -- cpp/libmps_parser/src/utilities/error.hpp | 6 +----- 2 files changed, 1 insertion(+), 7 deletions(-) diff --git a/cpp/include/cuopt/error.hpp b/cpp/include/cuopt/error.hpp index 9dd547adbb..9a8f62a428 100644 --- a/cpp/include/cuopt/error.hpp +++ b/cpp/include/cuopt/error.hpp @@ -100,9 +100,7 @@ inline void cuopt_expects(bool cond, error_type_t error_type, const char* fmt, . if (not cond) { va_list args; va_start(args, fmt); - char msg[2048]; - va_start(args, fmt); vsnprintf(msg, sizeof(msg), fmt, args); va_end(args); diff --git a/cpp/libmps_parser/src/utilities/error.hpp b/cpp/libmps_parser/src/utilities/error.hpp index 4ce68f5098..595a29059d 100644 --- a/cpp/libmps_parser/src/utilities/error.hpp +++ b/cpp/libmps_parser/src/utilities/error.hpp @@ -1,6 +1,6 @@ /* clang-format off */ /* - * SPDX-FileCopyrightText: Copyright (c) 2023-2025, NVIDIA CORPORATION & AFFILIATES. All rights reserved. + * SPDX-FileCopyrightText: Copyright (c) 2023-2026, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 */ /* clang-format on */ @@ -49,9 +49,7 @@ inline void mps_parser_expects(bool cond, error_type_t error_type, const char* f if (not cond) { va_list args; va_start(args, fmt); - char msg[2048]; - va_start(args, fmt); vsnprintf(msg, sizeof(msg), fmt, args); va_end(args); @@ -75,9 +73,7 @@ inline void mps_parser_expects_fatal(bool cond, error_type_t error_type, const c if (not cond) { va_list args; va_start(args, fmt); - char msg[2048]; - va_start(args, fmt); vsnprintf(msg, sizeof(msg), fmt, args); va_end(args); std::string error_string = error_to_string(error_type);