void-packages/srcpkgs/gawk/patches/fix-str2wstr.patch

51 lines
1.4 KiB
Diff

commit e05040b5d81b5a0e809fc56df2a7c3d654c77e1d
Author: Arnold D. Robbins <arnold@skeeve.com>
Date: Sun Jan 28 20:24:09 2024 +0200
Bug fix in str2wstr.
diff --git a/node.c b/node.c
index de12f05d..5aac5e88 100644
--- a/node.c
+++ b/node.c
@@ -815,6 +815,20 @@ str2wstr(NODE *n, size_t **ptr)
assert((n->flags & (STRING|STRCUR)) != 0);
+ /*
+ * For use by do_match, create and fill in an array.
+ * For each byte `i' in n->stptr (the original string),
+ * a[i] is equal to `j', where `j' is the corresponding wchar_t
+ * in the converted wide string.
+ *
+ * This is needed even for Nnull_string or Null_field.
+ *
+ * Create the array.
+ */
+ if (ptr != NULL) {
+ ezalloc(*ptr, size_t *, sizeof(size_t) * (n->stlen + 1), "str2wstr");
+ }
+
/*
* Don't convert global null string or global null field
* variables to a wide string. They are both zero-length anyway.
@@ -848,18 +862,6 @@ str2wstr(NODE *n, size_t **ptr)
emalloc(n->wstptr, wchar_t *, sizeof(wchar_t) * (n->stlen + 1), "str2wstr");
wsp = n->wstptr;
- /*
- * For use by do_match, create and fill in an array.
- * For each byte `i' in n->stptr (the original string),
- * a[i] is equal to `j', where `j' is the corresponding wchar_t
- * in the converted wide string.
- *
- * Create the array.
- */
- if (ptr != NULL) {
- ezalloc(*ptr, size_t *, sizeof(size_t) * (n->stlen + 1), "str2wstr");
- }
-
sp = n->stptr;
src_count = n->stlen;
memset(& mbs, 0, sizeof(mbs));