Skip to content

Commit 8987a1d

Browse files
committed
fixup: create/delete array at caller, esnure null-termination
1 parent cfc8d84 commit 8987a1d

File tree

3 files changed

+13
-9
lines changed

3 files changed

+13
-9
lines changed

XBMC Remote/SettingsValuesViewController.m

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -372,10 +372,13 @@ - (NSString*)getStringForSliderItem:(id)item value:(int)value {
372372
stringResult = [NSString stringWithFormat:format, value];
373373
}
374374
else {
375+
// Allocate fmtOutput here to use automatic dellocation once method is finished
376+
char fmtOutput[64];
377+
375378
// Since Kodi 18.x fmt formatting ("{0:d} ms") is used.
376-
const char *formatStr = [format UTF8String];
377-
char *string = convert_fmt(formatStr, value);
378-
stringResult = [NSString stringWithUTF8String:string];
379+
const char *fmtFormat = [format UTF8String];
380+
convert_fmt(fmtOutput, sizeof(fmtOutput), fmtFormat, value);
381+
stringResult = [NSString stringWithUTF8String:fmtOutput];
379382
}
380383
return stringResult;
381384
}

XBMC Remote/convert_fmt.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,10 @@
99
#include "convert_fmt.hpp"
1010
#include <fmt/core.h>
1111

12-
char* convert_fmt(const char *format, int value) {
13-
static char s[128];
14-
memset(s, 0, sizeof(s));
15-
fmt::format_to(s, format, value);
16-
return s;
12+
void convert_fmt(char *output, int size, const char *format, int value) {
13+
// Initialize char array with zeros
14+
memset(output, 0, size);
15+
16+
// Only fill up to size-1 to esnure null-termination
17+
fmt::format_to_n(output, size - 1, format, value);
1718
}

XBMC Remote/convert_fmt.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
extern "C" {
1313
#endif
1414

15-
extern char* convert_fmt(const char *format, int value);
15+
extern void convert_fmt(char *io, int size, const char *format, int value);
1616

1717
#ifdef __cplusplus
1818
}

0 commit comments

Comments
 (0)