summaryrefslogtreecommitdiff
path: root/games-util/grfcodec/files/6.0.6_p20210310/0001-Remove-brittle-apWrapper-code.patch
blob: e702f00160ced0a48006030f3d2ca876c39e5520 (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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
From 9e928c98c8ad0767607bc421b14ac289cdc6e536 Mon Sep 17 00:00:00 2001
From: David Seifert <soap@gentoo.org>
Date: Sat, 8 Oct 2022 16:29:43 +0200
Subject: [PATCH 1/2] Remove brittle `apWrapper` code

* This causes issues on musl, and generally doesn't make the
  code any simpler, while also creating lots of opportunities
  for undefined behavior.

Bug: https://bugs.gentoo.org/715910
---
 src/messages.cpp     | 14 ++++++++++----
 src/sanity.cpp       |  4 +++-
 src/sanity_defines.h | 23 -----------------------
 src/strings.cpp      |  9 +++++----
 4 files changed, 18 insertions(+), 32 deletions(-)

diff --git a/src/messages.cpp b/src/messages.cpp
index 385f217..3794f66 100644
--- a/src/messages.cpp
+++ b/src/messages.cpp
@@ -60,8 +60,11 @@ void ManualConsoleMessages(){
 }
 
 string mysprintf(const char*str,...){
-	WrapAp(str);
-	return myvsprintf(str,ap);
+	va_list ap;
+	va_start(ap, str);
+	string result = myvsprintf(str,ap);
+	va_end(ap);
+	return result;
 }
 
 #if defined DEBUG || defined _DEBUG
@@ -69,8 +72,11 @@ static RenumMessageId curMessage;
 #endif
 
 string IssueMessage(int minSan,RenumMessageId id,...){
-	WrapAp(id);
-	return vIssueMessage(minSan,id,ap);
+	va_list ap;
+	va_start(ap, id);
+	string result = vIssueMessage(minSan,id,ap);
+	va_end(ap);
+	return result;
 }
 
 string vIssueMessage(int minSan,RenumMessageId id,va_list& arg_ptr){
diff --git a/src/sanity.cpp b/src/sanity.cpp
index 844d840..0793a63 100644
--- a/src/sanity.cpp
+++ b/src/sanity.cpp
@@ -151,13 +151,15 @@ void Before8(int action){
 }
 
 bool CheckLength(int alen,int elen,RenumMessageId message,...){
-	WrapAp(message);
+	va_list ap;
+	va_start(ap, message);
 	if(alen<elen){
 		vIssueMessage(FATAL,message,ap);
 		return true;
 	}
 	if(alen>elen)
 		vIssueMessage(WARNING2,message,ap);
+	va_end(ap);
 	return false;
 }
 
diff --git a/src/sanity_defines.h b/src/sanity_defines.h
index d094f21..47f9c5f 100644
--- a/src/sanity_defines.h
+++ b/src/sanity_defines.h
@@ -22,7 +22,6 @@
 #ifndef _RENUM_SANITY_DEFS_H_INCLUDED_
 #define _RENUM_SANITY_DEFS_H_INCLUDED_
 
-#include <cstdarg>
 #include "message_mgr.h"
 
 bool CheckLength(int,int,RenumMessageId,...);
@@ -70,26 +69,4 @@ typedef auto_array<uint> Guintp;
 	type&operator[](uint x){return _p[x];}\
 	type operator[](uint x)const{return _p[x];}\
 
-class apWrapper{
-private:
-	va_list _ap;
-public:
-	~apWrapper(){va_end(_ap);}
-	operator va_list&(){return _ap;}
-	operator const va_list&()const{return _ap;}
-#ifdef __va_copy
-	va_list&operator=(va_list&ap){
-	    __va_copy(_ap,ap);
-		return _ap;
-	}
-#else
-	va_list const&operator=(va_list const&ap){
-	    return _ap=ap;
-	}
-#endif
-};
-#define WrapAp(v)\
-	apWrapper ap;\
-	va_start((va_list&)ap,v);
-
 #endif//_RENUM_SANITY_DEFS_H_INCLUDED_
diff --git a/src/strings.cpp b/src/strings.cpp
index 2512734..e184825 100644
--- a/src/strings.cpp
+++ b/src/strings.cpp
@@ -23,6 +23,7 @@
 #include<string>
 #include<cerrno>
 #include<cstdlib>
+#include<cstdarg>
 
 using namespace std;
 
@@ -396,15 +397,15 @@ static const uchar stackSize[]={0,1,2,2,4,2,8};
 
 string MakeStack(int items,...){
 	string ret;
-	WrapAp(items);
+	va_list ap;
+	va_start(ap, items);
 	uint item;
 	for(int i=0;i<items;i++){
-		item=va_arg(ap.operator va_list&(),uint);
-		//             ^^^^^^^^^^^^^^^^^^^
-		// gcc complains without that call.
+		item=va_arg(ap, uint);
 		VERIFY(item&&item<STACK_INVALID,item);
 		ret+=string(stackSize[item],char(item|i<<4));
 	}
+	va_end(ap);
 	return ret;
 }
 
-- 
2.38.0