commit e44998d575b849857ac9dc35548889e3aa6ccfb6
parent e45015a1d1f95c09a959e157df2a2dcce30b2b76
Author: Frederic Cambus <fred@statdns.com>
Date: Tue, 20 Oct 2020 11:24:12 +0200
Check strdup() return value and error out on failed allocations.
Diffstat:
1 file changed, 11 insertions(+), 5 deletions(-)
diff --git a/src/bdf2sfd.c b/src/bdf2sfd.c
@@ -4,7 +4,7 @@
* https://github.com/fcambus/bdf2sfd
*
* Created: 2019-11-21
- * Last Updated: 2020-06-12
+ * Last Updated: 2020-10-20
*
* bdf2sfd is released under the BSD 2-Clause license
* See LICENSE file for details
@@ -178,19 +178,24 @@ main(int argc, char *argv[])
switch(key) {
case FAMILY_NAME:
if (!font.name) {
- font.name = strdup(value);
+ if ((font.name = strdup(value)) == NULL)
+ error("Memory allocation error.");
+
name_allocated = true;
}
if (!font.psname) {
- font.psname = strdup(value);
+ if ((font.psname = strdup(value)) == NULL)
+ error("Memory allocation error.");
+
psname_allocated = true;
}
continue;
case COPYRIGHT:
- font.copyright = strdup(value);
+ if ((font.copyright = strdup(value)) == NULL)
+ error("Memory allocation error.");
continue;
@@ -243,7 +248,8 @@ main(int argc, char *argv[])
continue;
case FONT_VERSION:
- font.version = strdup(value);
+ if ((font.version = strdup(value)) == NULL)
+ error("Memory allocation error.");
continue;