Commit 03fb6fe6 authored by Martin Milata's avatar Martin Milata Committed by Rusty Russell

base64: fix assignment to wrong type, use ssize_t

Functions that returned int have been modified to return ssize_t
instead.

Found by gcc:

base64.c:196:11: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  if (more == -1) {
           ^
Signed-off-by: default avatarMartin Milata <martin@martinmilata.cz>
parent ae967050
...@@ -118,7 +118,7 @@ size_t base64_decoded_length(size_t srclen) ...@@ -118,7 +118,7 @@ size_t base64_decoded_length(size_t srclen)
return ((srclen+3)/4*3); return ((srclen+3)/4*3);
} }
int base64_decode_quartet_using_maps(const base64_maps_t *maps, char dest[3], ssize_t base64_decode_quartet_using_maps(const base64_maps_t *maps, char dest[3],
const char src[4]) const char src[4])
{ {
signed char a; signed char a;
...@@ -143,7 +143,7 @@ int base64_decode_quartet_using_maps(const base64_maps_t *maps, char dest[3], ...@@ -143,7 +143,7 @@ int base64_decode_quartet_using_maps(const base64_maps_t *maps, char dest[3],
} }
int base64_decode_tail_using_maps(const base64_maps_t *maps, char dest[3], ssize_t base64_decode_tail_using_maps(const base64_maps_t *maps, char dest[3],
const char * src, const size_t srclen) const char * src, const size_t srclen)
{ {
char longsrc[4]; char longsrc[4];
...@@ -178,7 +178,7 @@ ssize_t base64_decode_using_maps(const base64_maps_t *maps, ...@@ -178,7 +178,7 @@ ssize_t base64_decode_using_maps(const base64_maps_t *maps,
{ {
ssize_t dest_offset = 0; ssize_t dest_offset = 0;
ssize_t i; ssize_t i;
size_t more; ssize_t more;
if (destlen < base64_decoded_length(srclen)) { if (destlen < base64_decoded_length(srclen)) {
errno = EOVERFLOW; errno = EOVERFLOW;
......
...@@ -103,8 +103,8 @@ ssize_t base64_decode_using_maps(const base64_maps_t *maps, ...@@ -103,8 +103,8 @@ ssize_t base64_decode_using_maps(const base64_maps_t *maps,
* @return Number of decoded bytes set in dest. -1 on error (and errno set) * @return Number of decoded bytes set in dest. -1 on error (and errno set)
* @note sets errno = EDOM if src contains invalid characters * @note sets errno = EDOM if src contains invalid characters
*/ */
int base64_decode_quartet_using_maps(const base64_maps_t *maps, ssize_t base64_decode_quartet_using_maps(const base64_maps_t *maps,
char dest[3], const char src[4]); char dest[3], const char src[4]);
/** /**
* base64_decode_tail_using_maps - decode the final bytes of a base64 string using a specific alphabet * base64_decode_tail_using_maps - decode the final bytes of a base64 string using a specific alphabet
...@@ -116,8 +116,8 @@ int base64_decode_quartet_using_maps(const base64_maps_t *maps, ...@@ -116,8 +116,8 @@ int base64_decode_quartet_using_maps(const base64_maps_t *maps,
* @note sets errno = EDOM if src contains invalid characters * @note sets errno = EDOM if src contains invalid characters
* @note sets errno = EINVAL if src is an invalid base64 tail * @note sets errno = EINVAL if src is an invalid base64 tail
*/ */
int base64_decode_tail_using_maps(const base64_maps_t *maps, char *dest, ssize_t base64_decode_tail_using_maps(const base64_maps_t *maps, char *dest,
const char *src, size_t srclen); const char *src, size_t srclen);
/* the rfc4648 functions: */ /* the rfc4648 functions: */
...@@ -212,7 +212,7 @@ ssize_t base64_decode(char *dest, size_t destlen, ...@@ -212,7 +212,7 @@ ssize_t base64_decode(char *dest, size_t destlen,
* @note sets errno = EDOM if src contains invalid characters * @note sets errno = EDOM if src contains invalid characters
*/ */
static inline static inline
int base64_decode_quartet(char dest[3], const char src[4]) ssize_t base64_decode_quartet(char dest[3], const char src[4])
{ {
return base64_decode_quartet_using_maps(&base64_maps_rfc4648, return base64_decode_quartet_using_maps(&base64_maps_rfc4648,
dest, src); dest, src);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment