[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[pre-lexer 01/21] str: Make ss_alloc_substring() allocate null-terminate
From: |
Ben Pfaff |
Subject: |
[pre-lexer 01/21] str: Make ss_alloc_substring() allocate null-terminated strings. |
Date: |
Thu, 23 Sep 2010 21:20:37 -0700 |
This has little cost and it is occasionally valuable.
---
src/libpspp/str.c | 6 +++---
1 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/src/libpspp/str.c b/src/libpspp/str.c
index bde4de4..9f0cb6e 100644
--- a/src/libpspp/str.c
+++ b/src/libpspp/str.c
@@ -30,6 +30,7 @@
#include <relocatable.h>
#include "minmax.h"
#include "xalloc.h"
+#include "xmemdup0.h"
#include "xsize.h"
/* Reverses the order of NBYTES bytes at address P, thus converting
@@ -379,14 +380,13 @@ ss_tail (struct substring ss, size_t cnt)
return ss;
}
-/* Makes a malloc()'d copy of the contents of OLD
+/* Makes a malloc()'d, null-terminated copy of the contents of OLD
and stores it in NEW. */
void
ss_alloc_substring (struct substring *new, struct substring old)
{
- new->string = xmalloc (old.length);
+ new->string = xmemdup0 (old.string, old.length);
new->length = old.length;
- memcpy (new->string, old.string, old.length);
}
/* Allocates room for a CNT-character string in NEW. */
--
1.7.1
- [pre-lexer 00/21] preparation for work on lexer, Ben Pfaff, 2010/09/24
- [pre-lexer 01/21] str: Make ss_alloc_substring() allocate null-terminated strings.,
Ben Pfaff <=
- [pre-lexer 13/21] command: Remove superfluous trailing spaces from command names., Ben Pfaff, 2010/09/24
- [pre-lexer 19/21] data-in: Rewrite logic for recoding input, and get rid of src_enc member., Ben Pfaff, 2010/09/24
- [pre-lexer 03/21] i18n: New function recode_substring_pool()., Ben Pfaff, 2010/09/24
- [pre-lexer 11/21] lexer: Use lex_is_string() more consistently., Ben Pfaff, 2010/09/24
- [pre-lexer 04/21] syntax-string-source: Fix format string problems., Ben Pfaff, 2010/09/24
- [pre-lexer 08/21] Make translation easier., Ben Pfaff, 2010/09/24
- [pre-lexer 14/21] command: Add specific DATASET unimplemented commands., Ben Pfaff, 2010/09/24
- [pre-lexer 12/21] command: Remove INSERT from list of unimplemented commands., Ben Pfaff, 2010/09/24
- [pre-lexer 20/21] data-in: Make data_in() parameters more uniform., Ben Pfaff, 2010/09/24
- [pre-lexer 02/21] i18n: Use UTF8 macro instead of "UTF8" literal string., Ben Pfaff, 2010/09/24