X-Git-Url: http://www.wagner.pp.ru/gitweb/?p=oss%2Fcatdoc.git;a=blobdiff_plain;f=src%2Fcharsets.c;h=05118767815072f301bee1cd0f202d3249d55079;hp=4ee0f4c09902a63ff792451b1584d7b9461ec5a2;hb=73b1dd7326585b7c18ce6e24320656d0d6f843cc;hpb=a79f2377217c571396074fccf360e01032cd77bf diff --git a/src/charsets.c b/src/charsets.c index 4ee0f4c..0511876 100644 --- a/src/charsets.c +++ b/src/charsets.c @@ -14,7 +14,7 @@ char *charset_path=CHARSETPATH; char *source_csname=SOURCE_CHARSET, *dest_csname=TARGET_CHARSET; -short int * source_charset; +uint16_t * source_charset; int unknown_as_hex=0; char bad_char[]=UNKNOWN_CHAR; CHARSET target_charset; @@ -46,13 +46,14 @@ CHARSET make_reverse_map(short int *charset) { int i,j,k,l; short int *p; if (! charset) { + free(newmap); return NULL; } for (i=0;i<256;i++) { k= charset[i]; j= (unsigned)k>>8; if (!newmap[j]) { - newmap[j] = malloc(sizeof(short int *)*256); + newmap[j] = (short int *)malloc(sizeof(short int)*256); if (!newmap[j]) { fprintf(stderr,"Insufficient memory for charset\n"); exit(1); @@ -72,7 +73,7 @@ CHARSET make_reverse_map(short int *charset) { short int * read_charset(const char *filename) { char *path; FILE *f; - short int *new=calloc(sizeof(short int),256); + short int *new; int c; long int uc; path= find_file(stradd(filename,CHARSET_EXT),charset_path); @@ -89,6 +90,7 @@ short int * read_charset(const char *filename) { if (input_buffer) setvbuf(f,input_buffer,_IOFBF,FILE_BUFFER); /* defaults */ + new = calloc(sizeof(short int),256); for (c=0;c<32;c++) { new[c]=c; } @@ -97,6 +99,7 @@ short int * read_charset(const char *filename) { if (c<0||c>255||uc<0||(uc>0xFEFE&& uc!=0xFFFE)) { fprintf(stderr,"Invalid charset file %s\n",path); fclose(f); + free(new); return NULL; } new[c]=uc;