summaryrefslogtreecommitdiff
path: root/source3/lib
diff options
context:
space:
mode:
authorJeremy Allison <jra@samba.org>2011-03-30 10:27:04 -0700
committerJeremy Allison <jra@samba.org>2011-03-30 20:58:10 +0200
commitd546adeab54af123eff66cee61a487c88b6ba61b (patch)
tree663798349655444d882f491f61f2975a78503c2a /source3/lib
parent048471d14b3ed65fe83e8f225e03af925aaf0c47 (diff)
downloadsamba-d546adeab54af123eff66cee61a487c88b6ba61b.tar.gz
samba-d546adeab54af123eff66cee61a487c88b6ba61b.tar.bz2
samba-d546adeab54af123eff66cee61a487c88b6ba61b.zip
Change convert_string_internal() and convert_string_error() to bool return.
Move closer to makeing all convert_string_XXX functions return bool. Autobuild-User: Jeremy Allison <jra@samba.org> Autobuild-Date: Wed Mar 30 20:58:10 CEST 2011 on sn-devel-104
Diffstat (limited to 'source3/lib')
-rw-r--r--source3/lib/charcnv.c97
-rw-r--r--source3/lib/fstring.c14
2 files changed, 54 insertions, 57 deletions
diff --git a/source3/lib/charcnv.c b/source3/lib/charcnv.c
index 74685408d4..76fa968457 100644
--- a/source3/lib/charcnv.c
+++ b/source3/lib/charcnv.c
@@ -80,13 +80,15 @@ void init_iconv(void)
* @param srclen length of the source string in bytes
* @param dest pointer to destination string (multibyte or singlebyte)
* @param destlen maximal length allowed for string
- * @returns the number of bytes occupied in the destination
+ * @param converted size is the number of bytes occupied in the destination
+ *
+ * @returns false and sets errno on fail, true on success.
*
* Ensure the srclen contains the terminating zero.
*
**/
-static size_t convert_string_internal(charset_t from, charset_t to,
+static bool convert_string_internal(charset_t from, charset_t to,
void const *src, size_t srclen,
void *dest, size_t destlen, size_t *converted_size)
{
@@ -112,16 +114,18 @@ static size_t convert_string_internal(charset_t from, charset_t to,
if (descriptor == (smb_iconv_t)-1 || descriptor == (smb_iconv_t)0) {
errno = EINVAL;
- return (size_t)-1;
+ return false;
}
i_len=srclen;
o_len=destlen;
retval = smb_iconv(descriptor, &inbuf, &i_len, &outbuf, &o_len);
- if (converted_size != NULL)
- *converted_size = destlen-o_len;
- return retval;
+ if (retval == (size_t)-1) {
+ return false;
+ }
+ *converted_size = destlen-o_len;
+ return true;
}
/**
@@ -132,7 +136,9 @@ static size_t convert_string_internal(charset_t from, charset_t to,
* @param srclen length of the source string in bytes, or -1 for nul terminated.
* @param dest pointer to destination string (multibyte or singlebyte)
* @param destlen maximal length allowed for string - *NEVER* -1.
- * @returns the number of bytes occupied in the destination
+ * @param converted size is the number of bytes occupied in the destination
+ *
+ * @returns false and sets errno on fail, true on success.
*
* Ensure the srclen contains the terminating zero.
*
@@ -140,7 +146,7 @@ static size_t convert_string_internal(charset_t from, charset_t to,
* Don't change unless you really know what you are doing. JRA.
**/
-size_t convert_string_error(charset_t from, charset_t to,
+bool convert_string_error(charset_t from, charset_t to,
void const *src, size_t srclen,
void *dest, size_t destlen,
size_t *converted_size)
@@ -155,13 +161,11 @@ size_t convert_string_error(charset_t from, charset_t to,
SMB_ASSERT(destlen != (size_t)-1);
#endif
- if (converted_size) {
+ if (srclen == 0) {
*converted_size = 0;
+ return true;
}
- if (srclen == 0)
- return 0;
-
if (from != CH_UTF16LE && from != CH_UTF16BE && to != CH_UTF16LE && to != CH_UTF16BE) {
const unsigned char *p = (const unsigned char *)src;
unsigned char *q = (unsigned char *)dest;
@@ -185,26 +189,24 @@ size_t convert_string_error(charset_t from, charset_t to,
#ifdef BROKEN_UNICODE_COMPOSE_CHARACTERS
goto general_case;
#else
- size_t ret = convert_string_internal(from, to, p, slen, q, dlen, converted_size);
- if (converted_size) {
- *converted_size += retval;
- }
+ bool ret = convert_string_internal(from, to, p, slen, q, dlen, converted_size);
+ *converted_size += retval;
return ret;
#endif
}
}
- if (converted_size) {
- *converted_size = retval;
- }
+
+ *converted_size = retval;
+
if (!dlen) {
/* Even if we fast path we should note if we ran out of room. */
if (((slen != (size_t)-1) && slen) ||
((slen == (size_t)-1) && lastp)) {
errno = E2BIG;
- return (size_t)-1;
+ return false;
}
}
- return retval;
+ return true;
} else if (from == CH_UTF16LE && to != CH_UTF16LE) {
const unsigned char *p = (const unsigned char *)src;
unsigned char *q = (unsigned char *)dest;
@@ -229,26 +231,24 @@ size_t convert_string_error(charset_t from, charset_t to,
#ifdef BROKEN_UNICODE_COMPOSE_CHARACTERS
goto general_case;
#else
- size_t ret = convert_string_internal(from, to, p, slen, q, dlen, converted_size);
- if (converted_size) {
- *converted_size += retval;
- }
+ bool ret = convert_string_internal(from, to, p, slen, q, dlen, converted_size);
+ *converted_size += retval;
return ret;
#endif
}
}
- if (converted_size) {
- *converted_size = retval;
- }
+
+ *converted_size = retval;
+
if (!dlen) {
/* Even if we fast path we should note if we ran out of room. */
if (((slen != (size_t)-1) && slen) ||
((slen == (size_t)-1) && lastp)) {
errno = E2BIG;
- return (size_t)-1;
+ return false;
}
}
- return retval;
+ return true;
} else if (from != CH_UTF16LE && from != CH_UTF16BE && to == CH_UTF16LE) {
const unsigned char *p = (const unsigned char *)src;
unsigned char *q = (unsigned char *)dest;
@@ -273,26 +273,24 @@ size_t convert_string_error(charset_t from, charset_t to,
#ifdef BROKEN_UNICODE_COMPOSE_CHARACTERS
goto general_case;
#else
- size_t ret = convert_string_internal(from, to, p, slen, q, dlen, converted_size);
- if (converted_size) {
- *converted_size += retval;
- }
+ bool ret = convert_string_internal(from, to, p, slen, q, dlen, converted_size);
+ *converted_size += retval;
return ret;
#endif
}
}
- if (converted_size) {
- *converted_size = retval;
- }
+
+ *converted_size = retval;
+
if (!dlen) {
/* Even if we fast path we should note if we ran out of room. */
if (((slen != (size_t)-1) && slen) ||
((slen == (size_t)-1) && lastp)) {
errno = E2BIG;
- return (size_t)-1;
+ return false;
}
}
- return retval;
+ return true;
}
#ifdef BROKEN_UNICODE_COMPOSE_CHARACTERS
@@ -303,17 +301,19 @@ size_t convert_string_error(charset_t from, charset_t to,
size_t convert_string(charset_t from, charset_t to,
void const *src, size_t srclen,
- void *dest, size_t destlen) {
+ void *dest, size_t destlen)
+{
size_t converted_size;
- size_t retval = convert_string_error(from, to, src, srclen, dest, destlen, &converted_size);
- if(retval==(size_t)-1) {
+ bool ret = convert_string_error(from, to, src, srclen, dest, destlen, &converted_size);
+
+ if(ret==false) {
const char *reason="unknown error";
switch(errno) {
case EINVAL:
reason="Incomplete multibyte sequence";
DEBUG(3,("convert_string_internal: Conversion error: %s(%s)\n",
reason, (const char *)src));
- return (size_t)-1;
+ break;
case E2BIG:
{
struct smb_iconv_handle *ic;
@@ -336,15 +336,15 @@ size_t convert_string(charset_t from, charset_t to,
reason="Illegal multibyte sequence";
DEBUG(3,("convert_string_internal: Conversion error: %s(%s)\n",
reason, (const char *)src));
- return (size_t)-1;
+ break;
default:
DEBUG(0,("convert_string_internal: Conversion error: %s(%s)\n",
reason, (const char *)src));
- return (size_t)-1;
+ break;
}
/* smb_panic(reason); */
}
- return converted_size;
+ return ret ? converted_size : (size_t)-1;
}
@@ -380,11 +380,6 @@ bool convert_string_talloc(TALLOC_CTX *ctx, charset_t from, charset_t to,
*dest = NULL;
- if (!converted_size) {
- errno = EINVAL;
- return false;
- }
-
if (src == NULL || srclen == (size_t)-1) {
errno = EINVAL;
return false;
diff --git a/source3/lib/fstring.c b/source3/lib/fstring.c
index 74c2138975..50b0765f92 100644
--- a/source3/lib/fstring.c
+++ b/source3/lib/fstring.c
@@ -35,17 +35,19 @@ size_t push_ascii_fstring(void *dest, const char *src)
this function uses convert_string_error() to avoid common debug
warnings where is unable to convert strings to CH_DOS. The target
string is truncated at the first character that cannot be converted
- The target is always null terminated. The resulting string size,
- without the null termination, it returned
+ The target is always null terminated.
********************************************************************/
size_t push_ascii_nstring(void *dest, const char *src)
{
size_t converted_size = 0;
- size_t ret;
- ret = convert_string_error(CH_UNIX, CH_DOS, src, -1, dest, sizeof(nstring), &converted_size);
- SCVAL(dest, sizeof(nstring)-1, 0);
- return ret;
+ bool ret = convert_string_error(CH_UNIX, CH_DOS, src, -1, dest, sizeof(nstring), &converted_size);
+ if (ret) {
+ SCVAL(dest, sizeof(nstring)-1, 0);
+ } else {
+ SCVAL(dest, 0, 0);
+ }
+ return ret ? converted_size : (size_t)-1;
}
size_t pull_ascii_fstring(char *dest, const void *src)