[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH] libpoke: Use strndup instead of xstrndup
From: |
Tim Rühsen |
Subject: |
[PATCH] libpoke: Use strndup instead of xstrndup |
Date: |
Wed, 6 May 2020 16:32:22 +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 | 19 ++++++++++++++++---
3 files changed, 22 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..6d503648 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,14 @@ 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_ERROR (PKL_AST_LOC (print_stmt),
+ "out of memory");
+ PKL_TRANS_PAYLOAD->errors++;
+ PKL_PASS_ERROR;
+ }
}
/* Process the format string. */
@@ -841,7 +847,14 @@ 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_ERROR (PKL_AST_LOC (print_stmt),
+ "out of memory");
+ PKL_TRANS_PAYLOAD->errors++;
+ PKL_PASS_ERROR;
+ }
p = end;
}
}
--
2.26.2
- [PATCH] libpoke: Use strndup instead of xstrndup,
Tim Rühsen <=