File tree Expand file tree Collapse file tree 2 files changed +24
-21
lines changed Expand file tree Collapse file tree 2 files changed +24
-21
lines changed Original file line number Diff line number Diff line change @@ -211,6 +211,8 @@ mapi_attr_read (size_t len, unsigned char *buf)
211
211
CHECKINT32 (idx , len ); a -> names [i ].len = GETINT32 (buf + idx ); idx += 4 ;
212
212
213
213
/* read the data into a buffer */
214
+ /* read the data into a buffer */
215
+ assert (a -> names [i ].len != 0 );
214
216
assert (idx + a -> names [i ].len <= len );
215
217
a -> names [i ].data = unicode_to_utf8 (a -> names [i ].len , buf + idx );
216
218
Original file line number Diff line number Diff line change @@ -85,28 +85,29 @@ unicode_to_utf8 (size_t len, unsigned char* buf)
85
85
int j = 0 ;
86
86
unsigned char * utf8 = malloc (3 * len /2 + 1 ); /* won't get any longer than this */
87
87
88
- for (i = 0 ; i < len - 1 ; i += 2 )
89
- {
90
- uint32 c = GETINT16 (buf + i );
91
- if (c <= 0x007f )
92
- {
93
- utf8 [j ++ ] = 0x00 | ((c & 0x007f ) >> 0 );
94
- }
95
- else if (c < 0x07ff )
96
- {
97
- utf8 [j ++ ] = 0xc0 | ((c & 0x07c0 ) >> 6 );
98
- utf8 [j ++ ] = 0x80 | ((c & 0x003f ) >> 0 );
99
- }
100
- else
101
- {
102
- utf8 [j ++ ] = 0xe0 | ((c & 0xf000 ) >> 12 );
103
- utf8 [j ++ ] = 0x80 | ((c & 0x0fc0 ) >> 6 );
104
- utf8 [j ++ ] = 0x80 | ((c & 0x003f ) >> 0 );
105
- }
88
+ if (len > 0 ) {
89
+ for (i = 0 ; i < len - 1 ; i += 2 )
90
+ {
91
+ uint32 c = GETINT16 (buf + i );
92
+ if (c <= 0x007f )
93
+ {
94
+ utf8 [j ++ ] = 0x00 | ((c & 0x007f ) >> 0 );
95
+ }
96
+ else if (c < 0x07ff )
97
+ {
98
+ utf8 [j ++ ] = 0xc0 | ((c & 0x07c0 ) >> 6 );
99
+ utf8 [j ++ ] = 0x80 | ((c & 0x003f ) >> 0 );
100
+ }
101
+ else
102
+ {
103
+ utf8 [j ++ ] = 0xe0 | ((c & 0xf000 ) >> 12 );
104
+ utf8 [j ++ ] = 0x80 | ((c & 0x0fc0 ) >> 6 );
105
+ utf8 [j ++ ] = 0x80 | ((c & 0x003f ) >> 0 );
106
+ }
107
+ }
106
108
}
107
-
109
+
108
110
utf8 [j ] = '\0' ;
109
-
111
+
110
112
return utf8 ;
111
113
}
112
-
You can’t perform that action at this time.
0 commit comments