projects
/
pspp-builds.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
3939ba4
)
Make str_copy_rpad() behave properly with a DST_SIZE of 0.
author
Ben Pfaff
<blp@gnu.org>
Thu, 9 Oct 2008 14:37:43 +0000
(07:37 -0700)
committer
Ben Pfaff
<blp@gnu.org>
Sat, 11 Oct 2008 17:04:06 +0000
(10:04 -0700)
src/libpspp/str.c
patch
|
blob
|
history
diff --git
a/src/libpspp/str.c
b/src/libpspp/str.c
index 9a7c6da8bfa8c36e50cca3cfd7b7bfe99a6cf0db..d082672060f5235d6610939221365663fb5652b8 100644
(file)
--- a/
src/libpspp/str.c
+++ b/
src/libpspp/str.c
@@
-194,15
+194,18
@@
buf_copy_rpad (char *dst, size_t dst_size,
void
str_copy_rpad (char *dst, size_t dst_size, const char *src)
{
void
str_copy_rpad (char *dst, size_t dst_size, const char *src)
{
- size_t src_len = strlen (src);
- if (src_len < dst_size - 1)
+ if (dst_size > 0)
{
{
- memcpy (dst, src, src_len);
- memset (&dst[src_len], ' ', dst_size - 1 - src_len);
+ size_t src_len = strlen (src);
+ if (src_len < dst_size - 1)
+ {
+ memcpy (dst, src, src_len);
+ memset (&dst[src_len], ' ', dst_size - 1 - src_len);
+ }
+ else
+ memcpy (dst, src, dst_size - 1);
+ dst[dst_size - 1] = 0;
}
}
- else
- memcpy (dst, src, dst_size - 1);
- dst[dst_size - 1] = 0;
}
/* Copies SRC to DST, which is in a buffer DST_SIZE bytes long.
}
/* Copies SRC to DST, which is in a buffer DST_SIZE bytes long.