Const correctness on src char pointers for unicode/ascii conversion

This commit is contained in:
Nyall Dawson 2020-08-13 12:04:16 +10:00
parent 362938f17c
commit 1846fab4e6
2 changed files with 10 additions and 8 deletions

View File

@ -594,8 +594,8 @@ int mdb_get_option(unsigned long optnum);
void mdb_debug(int klass, char *fmt, ...);
/* iconv.c */
int mdb_unicode2ascii(MdbHandle *mdb, char *src, size_t slen, char *dest, size_t dlen);
int mdb_ascii2unicode(MdbHandle *mdb, char *src, size_t slen, char *dest, size_t dlen);
int mdb_unicode2ascii(MdbHandle *mdb, const char *src, size_t slen, char *dest, size_t dlen);
int mdb_ascii2unicode(MdbHandle *mdb, const char *src, size_t slen, char *dest, size_t dlen);
void mdb_iconv_init(MdbHandle *mdb);
void mdb_iconv_close(MdbHandle *mdb);
const char* mdb_target_charset(MdbHandle *mdb);

View File

@ -31,12 +31,13 @@
* This function is used in reading text data from an MDB table.
*/
int
mdb_unicode2ascii(MdbHandle *mdb, char *src, size_t slen, char *dest, size_t dlen)
mdb_unicode2ascii(MdbHandle *mdb, const char *src, size_t slen, char *dest, size_t dlen)
{
char *tmp = NULL;
size_t tlen = 0;
size_t len_in, len_out;
char *in_ptr, *out_ptr;
const char *in_ptr = NULL;
char *out_ptr = NULL;
if ((!src) || (!dest) || (!dlen))
return 0;
@ -73,7 +74,7 @@ mdb_unicode2ascii(MdbHandle *mdb, char *src, size_t slen, char *dest, size_t dle
#if HAVE_ICONV
//printf("1 len_in %d len_out %d\n",len_in, len_out);
while (1) {
iconv(mdb->iconv_in, &in_ptr, &len_in, &out_ptr, &len_out);
iconv(mdb->iconv_in, (char **)&in_ptr, &len_in, &out_ptr, &len_out);
/*
* Have seen database with odd number of bytes in UCS-2, shouldn't happen but protect against it
*/
@ -114,10 +115,11 @@ mdb_unicode2ascii(MdbHandle *mdb, char *src, size_t slen, char *dest, size_t dle
* If slen is 0, strlen will be used to calculate src's length.
*/
int
mdb_ascii2unicode(MdbHandle *mdb, char *src, size_t slen, char *dest, size_t dlen)
mdb_ascii2unicode(MdbHandle *mdb, const char *src, size_t slen, char *dest, size_t dlen)
{
size_t len_in, len_out;
char *in_ptr, *out_ptr;
const char *in_ptr = NULL;
char *out_ptr = NULL;
if ((!src) || (!dest) || (!dlen))
return 0;
@ -128,7 +130,7 @@ mdb_ascii2unicode(MdbHandle *mdb, char *src, size_t slen, char *dest, size_t dle
len_out = dlen;
#ifdef HAVE_ICONV
iconv(mdb->iconv_out, &in_ptr, &len_in, &out_ptr, &len_out);
iconv(mdb->iconv_out, (char **)&in_ptr, &len_in, &out_ptr, &len_out);
//printf("len_in %d len_out %d\n", len_in, len_out);
dlen -= len_out;
#else