From 02b539b2449fee2cf1f3df43378bb8f55801ab61 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Wilfried=20G=C3=B6esgens?= Date: Wed, 27 Feb 2008 23:06:49 +0000 Subject: [PATCH] * safestrncpy counts the copied string anyway, and nobody needs the returned pointer -> return a long -> return the number of copied bytes. -> return negative values if we hit the boundary. --- libcitadel/debian/files | 6 +++--- libcitadel/lib/libcitadel.h | 2 +- libcitadel/lib/tools.c | 14 ++++++++++---- 3 files changed, 14 insertions(+), 8 deletions(-) diff --git a/libcitadel/debian/files b/libcitadel/debian/files index 525ce5997..86dbb72dd 100644 --- a/libcitadel/debian/files +++ b/libcitadel/debian/files @@ -1,3 +1,3 @@ -libcitadel1_1.05-4_i386.deb libs optional -libcitadel1-dbg_1.05-4_i386.deb libdevel optional -libcitadel-dev_1.05-4_i386.deb libdevel optional +libcitadel1_1.06-7_i386.deb libs optional +libcitadel1-dbg_1.06-7_i386.deb libdevel optional +libcitadel-dev_1.06-7_i386.deb libdevel optional diff --git a/libcitadel/lib/libcitadel.h b/libcitadel/lib/libcitadel.h index 7dac9e971..5d8040950 100644 --- a/libcitadel/lib/libcitadel.h +++ b/libcitadel/lib/libcitadel.h @@ -188,7 +188,7 @@ void ShutDownLibCitadel(void); -char *safestrncpy(char *dest, const char *src, size_t n); +int safestrncpy(char *dest, const char *src, size_t n); int num_tokens (const char *source, char tok); long extract_token(char *dest, const char *source, int parmnum, char separator, int maxlen); long grab_token(char **dest, const char *source, int parmnum, char separator); diff --git a/libcitadel/lib/tools.c b/libcitadel/lib/tools.c index 17981796e..c056fe94d 100644 --- a/libcitadel/lib/tools.c +++ b/libcitadel/lib/tools.c @@ -73,8 +73,14 @@ const byte dtable[256] = { 128, 128, 0 }; - -char *safestrncpy(char *dest, const char *src, size_t n) +/** + * \brief copy a string into a buffer of a known size. abort if we exceed the limits + * \param dest the targetbuffer + * \param src the source string + * \param n the size od dest + * \returns the number of characters copied if dest is big enough, -n if not. + */ +int safestrncpy(char *dest, const char *src, size_t n) { int i = 0; @@ -85,11 +91,11 @@ char *safestrncpy(char *dest, const char *src, size_t n) do { dest[i] = src[i]; - if (dest[i] == 0) return(dest); + if (dest[i] == 0) return i; ++i; } while (i