dlugolecki.net.pl
Dziennik
Polecane
Software
projects
/
gedcom-parse.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
bd6f144
)
Handle illegal characters in to_internal (to avoid crashes).
author
Peter Verthez
<Peter.Verthez@advalvas.be>
Fri, 16 Aug 2002 16:21:09 +0000
(16:21 +0000)
committer
Peter Verthez
<Peter.Verthez@advalvas.be>
Fri, 16 Aug 2002 16:21:09 +0000
(16:21 +0000)
gedcom/encoding.c
patch
|
blob
|
history
diff --git
a/gedcom/encoding.c
b/gedcom/encoding.c
index d97f63c99aec7a971be936f73b92dd45125d4003..315b4adfe425e83c4bc8e1ea310551074e702a94 100644
(file)
--- a/
gedcom/encoding.c
+++ b/
gedcom/encoding.c
@@
-233,9
+233,11
@@
void close_conv_to_internal()
char* to_internal(char* str, size_t len,
char* output_buffer, size_t out_len)
{
char* to_internal(char* str, size_t len,
char* output_buffer, size_t out_len)
{
+ size_t res;
size_t outsize = out_len;
char *wrptr = output_buffer;
char *rdptr = conv_buf;
size_t outsize = out_len;
char *wrptr = output_buffer;
char *rdptr = conv_buf;
+ char *retval = output_buffer;
/* set up input buffer (concatenate to what was left previous time) */
/* can't use strcpy, because possible null bytes from unicode */
memcpy(conv_buf + conv_buf_size, str, len);
/* set up input buffer (concatenate to what was left previous time) */
/* can't use strcpy, because possible null bytes from unicode */
memcpy(conv_buf + conv_buf_size, str, len);
@@
-243,9
+245,18
@@
char* to_internal(char* str, size_t len,
/* set up output buffer (empty it) */
memset(output_buffer, 0, out_len);
/* do the conversion */
/* set up output buffer (empty it) */
memset(output_buffer, 0, out_len);
/* do the conversion */
- iconv(cd_to_internal, &rdptr, &conv_buf_size, &wrptr, &outsize);
+ res = iconv(cd_to_internal, &rdptr, &conv_buf_size, &wrptr, &outsize);
+ if (res == (size_t)-1) {
+ if (errno == EILSEQ) {
+ /* restart from an empty state and return NULL */
+ iconv(cd_to_internal, NULL, NULL, NULL, NULL);
+ retval = NULL;
+ rdptr++;
+ conv_buf_size--;
+ }
+ }
/* then shift what is left over to the head of the input buffer */
memmove(conv_buf, rdptr, conv_buf_size);
memset(conv_buf + conv_buf_size, 0, sizeof(conv_buf) - conv_buf_size);
/* then shift what is left over to the head of the input buffer */
memmove(conv_buf, rdptr, conv_buf_size);
memset(conv_buf + conv_buf_size, 0, sizeof(conv_buf) - conv_buf_size);
- return
output_buffer
;
+ return
retval
;
}
}