From 7a454ef4f6642dc63ddc098dda4f17be9be574de Mon Sep 17 00:00:00 2001 From: William Smith Date: Sat, 12 Jan 2013 22:41:54 -0500 Subject: [PATCH] base64: add proper const attribute to function arguments Add proper const attribute to function arguments in base64. const attribute is added to function arguments and variables in order to allow compiler checks with -Wbad-function-cast, -Wcast-qual and -Wwrite-strings warnings options. --- include/tropicssl/base64.h | 4 ++-- library/base64.c | 11 ++++++----- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/include/tropicssl/base64.h b/include/tropicssl/base64.h index 013f6fe..98de447 100644 --- a/include/tropicssl/base64.h +++ b/include/tropicssl/base64.h @@ -58,7 +58,7 @@ extern "C" { * required buffer size in *dlen */ int base64_encode(unsigned char *dst, int *dlen, - unsigned char *src, int slen); + const unsigned char *src, int slen); /** * \brief Decode a base64-formatted buffer @@ -77,7 +77,7 @@ extern "C" { * required buffer size in *dlen */ int base64_decode(unsigned char *dst, int *dlen, - unsigned char *src, int slen); + const unsigned char *src, int slen); /** * \brief Checkup routine diff --git a/library/base64.c b/library/base64.c index d313d38..6d773c8 100644 --- a/library/base64.c +++ b/library/base64.c @@ -68,7 +68,7 @@ static const unsigned char base64_dec_map[128] = { /* * Encode a buffer into base64 format */ -int base64_encode(unsigned char *dst, int *dlen, unsigned char *src, int slen) +int base64_encode(unsigned char *dst, int *dlen, const unsigned char *src, int slen) { int i, n; int C1, C2, C3; @@ -132,7 +132,7 @@ int base64_encode(unsigned char *dst, int *dlen, unsigned char *src, int slen) /* * Decode a base64-formatted buffer */ -int base64_decode(unsigned char *dst, int *dlen, unsigned char *src, int slen) +int base64_decode(unsigned char *dst, int *dlen, const unsigned char *src, int slen) { int i, j, n; unsigned long x; @@ -216,13 +216,14 @@ static const unsigned char base64_test_enc[] = int base64_self_test(int verbose) { int len; - unsigned char *src, buffer[128]; + unsigned char buffer[128]; + const unsigned char *src; if (verbose != 0) printf(" Base64 encoding test: "); len = sizeof(buffer); - src = (unsigned char *)base64_test_dec; + src = base64_test_dec; if (base64_encode(buffer, &len, src, 64) != 0 || memcmp(base64_test_enc, buffer, 88) != 0) { @@ -236,7 +237,7 @@ int base64_self_test(int verbose) printf("passed\n Base64 decoding test: "); len = sizeof(buffer); - src = (unsigned char *)base64_test_enc; + src = base64_test_enc; if (base64_decode(buffer, &len, src, 88) != 0 || memcmp(base64_test_dec, buffer, 64) != 0) { -- 2.11.4.GIT