Line 0
Link Here
|
|
|
1 |
--- filetype.bak.c Sat May 13 22:51:32 2006 |
2 |
+++ filetype.c Thu Aug 3 09:23:35 2006 |
3 |
@@ -66,8 +66,9 @@ |
4 |
} |
5 |
|
6 |
#define CHECK_SIZE(db,array,type,size) if(db->array##_num >= db->array##_size){\ |
7 |
- if((newdata=realloc(db->array,db->array##_size+size*sizeof(type)))==NULL)\ |
8 |
+ if((newdata=realloc(db->array,(db->array##_size+size)*sizeof(type)))==NULL)\ |
9 |
return -1;\ |
10 |
+ db->array##_size +=size; \ |
11 |
db->array =newdata;\ |
12 |
} |
13 |
|
14 |
@@ -80,7 +81,7 @@ |
15 |
struct ci_data_type *newdata; |
16 |
int indx,i; |
17 |
|
18 |
- CHECK_SIZE(db,types,struct ci_data_type,50); |
19 |
+ CHECK_SIZE(db,types,struct ci_data_type,50) |
20 |
|
21 |
indx=db->types_num; |
22 |
db->types_num++; |
23 |
@@ -113,7 +114,7 @@ |
24 |
int indx; |
25 |
|
26 |
CHECK_SIZE(db,magics,struct ci_magic,50) |
27 |
- |
28 |
+ |
29 |
indx=db->magics_num; |
30 |
db->magics_num++; |
31 |
|
32 |
@@ -308,6 +309,10 @@ |
33 |
} |
34 |
groups[i]=-1; |
35 |
type=types_add(db,record.type,record.descr,groups); |
36 |
+ if(type<0){ |
37 |
+ ret=-2; |
38 |
+ break; |
39 |
+ } |
40 |
} |
41 |
|
42 |
magics_add(db,record.offset,record.magic,record.len,type); |
43 |
@@ -459,10 +464,13 @@ |
44 |
int endian=0; |
45 |
/*check for utf8 ........*/ |
46 |
for(i=0;i<buflen;i+=ret){ |
47 |
- if(!(ret=isUTF8(buf+i,buflen-i))) |
48 |
+ if((ret=isUTF8(buf+i,buflen-i)) <= 0) |
49 |
break; |
50 |
} |
51 |
|
52 |
+ if(ret < 0 && i == 0) |
53 |
+ ret=0;/*Not enough data to check*/ |
54 |
+ |
55 |
if(ret) /*Even if the last char is unknown ret!=0 mean is utf*/ |
56 |
return CI_UTF_DATA; /*... but what about if buflen is about 2 or 3 bytes long ?*/ |
57 |
|
58 |
@@ -500,7 +508,7 @@ |
59 |
|
60 |
if((ret=check_magics(db,buf,buflen))>=0) |
61 |
return ret; |
62 |
- |
63 |
+ |
64 |
/*At the feature the check_ascii and check_unicode must be merged ....*/ |
65 |
if((ret=check_ascii((unsigned char *)buf,buflen))>0) |
66 |
return ret; |
67 |
@@ -508,7 +516,7 @@ |
68 |
if((ret=check_unicode((unsigned char *)buf,buflen))>0){ |
69 |
return CI_UTF_DATA; |
70 |
} |
71 |
- |
72 |
+ |
73 |
return CI_BIN_DATA; /*binary data*/ |
74 |
} |
75 |
|