summaryrefslogtreecommitdiffstats
path: root/libass
diff options
context:
space:
mode:
authorOneric <oneric@oneric.stub>2020-07-07 23:08:05 +0200
committerOleg Oshmyan <chortos@inbox.lv>2020-10-27 01:03:04 +0200
commitb4f27d26079a3de98c4669eae8e11a2088494afb (patch)
tree10667e98c71f1c80b7f653af3ea92f6b30e4c18b /libass
parentadd83539899242bf8ddbbac28fe2fde17c4c0bce (diff)
downloadlibass-b4f27d26079a3de98c4669eae8e11a2088494afb.tar.bz2
libass-b4f27d26079a3de98c4669eae8e11a2088494afb.tar.xz
Make STRVAL macros strdup-fail safe
Strictly speaking this is not neccessary in regular processing as the event and font fields are intialised with zeroes anyway and there's no old value to fallback too. However when processing style overrides, this can prevent a non-null value being replaced by NULL. This commit also gets rid of the unneccessary '!= NULL' check. Passing NULL to free is well defined and safe.
Diffstat (limited to 'libass')
-rw-r--r--libass/ass.c14
1 files changed, 10 insertions, 4 deletions
diff --git a/libass/ass.c b/libass/ass.c
index b64b070..afb511c 100644
--- a/libass/ass.c
+++ b/libass/ass.c
@@ -266,14 +266,20 @@ static long long string2timecode(ASS_Library *library, char *p)
#define STRVAL(name) \
} else if (ass_strcasecmp(tname, #name) == 0) { \
- if (target->name != NULL) free(target->name); \
- target->name = strdup(token);
+ char *new_str = strdup(token); \
+ if (new_str) { \
+ free(target->name); \
+ target->name = new_str; \
+ }
#define STARREDSTRVAL(name) \
} else if (ass_strcasecmp(tname, #name) == 0) { \
- if (target->name != NULL) free(target->name); \
while (*token == '*') ++token; \
- target->name = strdup(token);
+ char *new_str = strdup(token); \
+ if (new_str) { \
+ free(target->name); \
+ target->name = new_str; \
+ }
#define COLORVAL(name) ANYVAL(name,parse_color_header)
#define INTVAL(name) ANYVAL(name,atoi)