blob: 850307520868389fe6ededd7e056adb89e13dc25 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
|
From 96ce0e7bc5ff6ced72f6ba072ac592024d3e9f81 Mon Sep 17 00:00:00 2001
From: Conrad Poelman <cpgithub@stellarscience.com>
Date: Tue, 5 Oct 2021 15:50:36 -0400
Subject: [PATCH] NULL->string() to eliminate UB, support MSVC 2022
Per https://www.cplusplus.com/reference/string/string/string: "If s is a null pointer ... it causes undefined behavior."
This article by C++ Standards Committee member Aaron Ballman reinforces that: https://wiki.sei.cmu.edu/confluence/display/cplusplus/STR51-CPP.+Do+not+attempt+to+create+a+std%3A%3Astring+from+a+null+pointer
The MSVC 2022 Preview release, with /std:c++latest, flags this lines as an error.
---
src/Utilities/StringTokenizer.cpp | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/Utilities/StringTokenizer.cpp b/src/Utilities/StringTokenizer.cpp
index 6a37b50..d50ace3 100644
--- a/src/Utilities/StringTokenizer.cpp
+++ b/src/Utilities/StringTokenizer.cpp
@@ -221,7 +221,7 @@ namespace ColPack
if (TokenStringLength == 0)
{
- return(NULL);
+ return string();
}
if (DelimiterStringLength == 0)
|