Skip to content

Commit cce3580

Browse files
committed
xrCore/_std_extensions.h: added missing va_end()
Formatting, placed xr_strcpy and xr_strcat together
1 parent dcf2a0e commit cce3580

File tree

1 file changed

+25
-17
lines changed

1 file changed

+25
-17
lines changed

src/xrCore/_std_extensions.h

Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ IC int xr_sprintf(char* dest, size_t sizeOfBuffer, const char* format, ...)
5959
#endif // _EDITOR
6060

6161
#if defined(LINUX)
62-
IC int vsnprintf_s( char *buffer, size_t size, size_t count, const char *format, va_list list)
62+
IC int vsnprintf_s(char* buffer, size_t size, size_t count, const char* format, va_list list)
6363
{
6464
//TODO add bound check
6565
return vsnprintf(buffer, size, format, list);
@@ -156,24 +156,40 @@ inline int xr_strcpy(LPSTR destination, size_t const destination_size, LPCSTR so
156156
return strcpy_s(destination, destination_size, source);
157157
}
158158

159+
template <int count>
160+
inline int xr_strcpy(char(&destination)[count], LPCSTR source)
161+
{
162+
return xr_strcpy(destination, count, source);
163+
}
164+
159165
inline int xr_strcat(LPSTR destination, size_t const buffer_size, LPCSTR source)
160166
{
161167
return strcat_s(destination, buffer_size, source);
162168
}
163169

170+
template <int count>
171+
inline int xr_strcat(char(&destination)[count], LPCSTR source)
172+
{
173+
return xr_strcat(destination, count, source);
174+
}
175+
164176
inline int __cdecl xr_sprintf(LPSTR destination, size_t const buffer_size, LPCSTR format_string, ...)
165177
{
166178
va_list args;
167179
va_start(args, format_string);
168-
return vsprintf_s(destination, buffer_size, format_string, args);
180+
const int result = vsprintf_s(destination, buffer_size, format_string, args);
181+
va_end(args);
182+
return result;
169183
}
170184

171185
template <int count>
172186
inline int __cdecl xr_sprintf(char (&destination)[count], LPCSTR format_string, ...)
173187
{
174188
va_list args;
175189
va_start(args, format_string);
176-
return vsprintf_s(destination, count, format_string, args);
190+
const int result = vsprintf_s(destination, count, format_string, args);
191+
va_end(args);
192+
return result;
177193
}
178194
#else // #ifndef MASTER_GOLD
179195

@@ -201,29 +217,21 @@ inline int __cdecl xr_sprintf(LPSTR destination, size_t const buffer_size, LPCST
201217
{
202218
va_list args;
203219
va_start(args, format_string);
204-
return vsnprintf_s(destination, buffer_size, buffer_size - 1, format_string, args);
220+
const int result = vsnprintf_s(destination, buffer_size, buffer_size - 1, format_string, args);
221+
va_end(args);
222+
return result;
205223
}
206224

207225
template <int count>
208226
inline int __cdecl xr_sprintf(char (&destination)[count], LPCSTR format_string, ...)
209227
{
210228
va_list args;
211229
va_start(args, format_string);
212-
return vsnprintf_s(destination, count, count - 1, format_string, args);
230+
const int result = vsnprintf_s(destination, count, count - 1, format_string, args);
231+
va_end(args);
232+
return result;
213233
}
214234
#endif // #ifndef MASTER_GOLD
215-
216-
template <int count>
217-
inline int xr_strcpy(char (&destination)[count], LPCSTR source)
218-
{
219-
return xr_strcpy(destination, count, source);
220-
}
221-
222-
template <int count>
223-
inline int xr_strcat(char (&destination)[count], LPCSTR source)
224-
{
225-
return xr_strcat(destination, count, source);
226-
}
227235
//#endif // #ifndef _EDITOR
228236

229237
inline void MemFill32(void* dst, u32 value, size_t dstSize)

0 commit comments

Comments
 (0)