Compare commits

..

7 Commits

Author SHA1 Message Date
Laurence Withers f2462dbeab Bump version 2009-11-03 23:10:15 +00:00
Laurence Withers 22d58219e7 Bump version 2009-11-03 23:10:15 +00:00
Laurence Withers 3cfd83e1a6 Fix potential null pointer dereference
utf8_encoder() was incorrectly dereferencing the pointer `state' before testing
it against null; fix by removing the variable initialisers.
2009-11-03 23:08:55 +00:00
Laurence Withers 0275295c88 Bump version 2009-10-14 15:27:52 +00:00
Laurence Withers 7e9085def4 Bump version 2009-10-14 15:27:52 +00:00
Laurence Withers b04ebb80e6 utf8_decode_char2(): fix return value
The return value of utf8_decode_char2() was 0, not (wchar_t)-1 as stated in the
documentation. Fix it.
2009-10-14 15:27:07 +00:00
Laurence Withers f2569b9423 utf8_decode_char2(): fix overlength char test
The test for an overlength character was incorrect; it was comparing only
the last byte decoded rather than the whole char. Fix it.
2009-10-14 15:24:08 +00:00
4 changed files with 14 additions and 12 deletions

View File

@ -24,7 +24,7 @@ utf8_decode_char2(const char* src, size_t size, size_t* used)
if(!src || !size) { if(!src || !size) {
errno = EINVAL; errno = EINVAL;
return 0; return (wchar_t)-1;
} }
if(used) *used = 1; if(used) *used = 1;
ch = *src++; ch = *src++;
@ -57,26 +57,26 @@ utf8_decode_char2(const char* src, size_t size, size_t* used)
ret = ch & 0x01; ret = ch & 0x01;
} else { } else {
errno = EILSEQ; errno = EILSEQ;
return 0; return (wchar_t)-1;
} }
while(remain--) { while(remain--) {
if(!--size) { if(!--size) {
errno = EILSEQ; errno = EILSEQ;
return 0; return (wchar_t)-1;
} }
ch = *src++; ch = *src++;
if((ch & 0xC0) != 0x80) { if((ch & 0xC0) != 0x80) {
errno = EILSEQ; errno = EILSEQ;
return 0; return (wchar_t)-1;
} }
ret <<= 6; ret <<= 6;
ret |= ch & 0x3F; ret |= ch & 0x3F;
} }
if(ch < min) { if(ret < min) {
errno = EILSEQ; errno = EILSEQ;
return 0; return (wchar_t)-1;
} }
return ret; return ret;
@ -104,7 +104,7 @@ utf8_decode_char2_force(const char* src, size_t size, size_t* used,
if(!src || !size) { if(!src || !size) {
errno = EINVAL; errno = EINVAL;
return 0; return (wchar_t)-1;
} }
if(used) *used = 1; if(used) *used = 1;
ch = *src++; ch = *src++;
@ -143,7 +143,7 @@ utf8_decode_char2_force(const char* src, size_t size, size_t* used,
ret |= ch & 0x3F; ret |= ch & 0x3F;
} }
if(ch < min) goto ILSEQ; if(ret < min) goto ILSEQ;
return ret; return ret;
} }

View File

@ -10,8 +10,7 @@
struct utf8_encode_state* struct utf8_encode_state*
utf8_encoder(struct utf8_encode_state* state) utf8_encoder(struct utf8_encode_state* state)
{ {
char* wr = state->wr, * ret; char* wr, * ret, * endp;
char* endp = wr + state->wr_size - 1;
wchar_t ch; wchar_t ch;
enum utf8_encode_error_action error_action; enum utf8_encode_error_action error_action;
int reencoding; int reencoding;
@ -21,6 +20,9 @@ utf8_encoder(struct utf8_encode_state* state)
return 0; return 0;
} }
wr = state->wr;
endp = wr + state->wr_size - 1;
state->written = 0; state->written = 0;
while(state->rd_remain) { while(state->rd_remain) {
ch = *state->rd; ch = *state->rd;

View File

@ -12,4 +12,4 @@
SOMAJOR=1 SOMAJOR=1
# SOMICRO is bumped every time there is a binary-compatible release. # SOMICRO is bumped every time there is a binary-compatible release.
SOMICRO=0 SOMICRO=2

View File

@ -11,7 +11,7 @@
# expected to be in 'major.minor.micro' format. # expected to be in 'major.minor.micro' format.
VERMAJOR=1 VERMAJOR=1
VERMINOR=3 VERMINOR=3
VERMICRO=0 VERMICRO=2
# kate: replace-trailing-space-save true; space-indent true; tab-width 4; # kate: replace-trailing-space-save true; space-indent true; tab-width 4;
# vim: expandtab:ts=4:sw=4:syntax=sh # vim: expandtab:ts=4:sw=4:syntax=sh