[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 2/2] libpoke: Use strndup instead of xstrndup
From: |
Tim Rühsen |
Subject: |
[PATCH 2/2] libpoke: Use strndup instead of xstrndup |
Date: |
Thu, 7 May 2020 10:15:27 +0200 |
2020-05-06 Tim Rühsen <address@hidden>
* bootstrap.conf: Remove xstrndup from libpoke_modules.
* libpoke/pkl-trans.c (pkl_trans1_ps_print_stmt): Use strndup
instead of xstrndup.
---
ChangeLog | 6 ++++++
bootstrap.conf | 1 -
libpoke/pkl-trans.c | 15 ++++++++++++---
3 files changed, 18 insertions(+), 4 deletions(-)
diff --git a/bootstrap.conf b/bootstrap.conf
index 3cf1b953..6e58d788 100644
--- a/bootstrap.conf
+++ b/bootstrap.conf
@@ -81,7 +81,6 @@ libpoke_modules="
tempname
tmpdir
xalloc
- xstrndup
"
# TODO: Remove this after the 1.0 release. Until then, this helps developers
diff --git a/libpoke/pkl-trans.c b/libpoke/pkl-trans.c
index a8fba37e..b3c354be 100644
--- a/libpoke/pkl-trans.c
+++ b/libpoke/pkl-trans.c
@@ -24,7 +24,6 @@
#include <string.h>
#include <xalloc.h>
#include <stdlib.h>
-#include "xstrndup.h"
#include "pk-utils.h"
@@ -572,7 +571,12 @@ PKL_PHASE_BEGIN_HANDLER (pkl_trans1_ps_print_stmt)
if (*p != '%')
{
p = strchrnul (fmt, '%');
- PKL_AST_PRINT_STMT_PREFIX (print_stmt) = xstrndup (fmt, p - fmt);
+ PKL_AST_PRINT_STMT_PREFIX (print_stmt) = strndup (fmt, p - fmt);
+ if (!PKL_AST_PRINT_STMT_PREFIX (print_stmt))
+ {
+ PKL_TRANS_PAYLOAD->errors++;
+ PKL_ICE (PKL_AST_LOC (print_stmt), _("out of memory"));
+ }
}
/* Process the format string. */
@@ -841,7 +845,12 @@ PKL_PHASE_BEGIN_HANDLER (pkl_trans1_ps_print_stmt)
if (*p != '\0' && *p != '%')
{
char *end = strchrnul (p, '%');
- PKL_AST_PRINT_STMT_ARG_SUFFIX (arg) = xstrndup (p, end - p);
+ PKL_AST_PRINT_STMT_ARG_SUFFIX (arg) = strndup (p, end - p);
+ if (!PKL_AST_PRINT_STMT_ARG_SUFFIX (arg))
+ {
+ PKL_TRANS_PAYLOAD->errors++;
+ PKL_ICE (PKL_AST_LOC (print_stmt), _("out of memory"));
+ }
p = end;
}
}
--
2.26.2