Changes in boot/generic/src/str.c [002fd5f:a35b458] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
boot/generic/src/str.c
r002fd5f ra35b458 141 141 if (*offset + 1 > size) 142 142 return 0; 143 143 144 144 /* First byte read from string */ 145 145 uint8_t b0 = (uint8_t) str[(*offset)++]; 146 146 147 147 /* Determine code length */ 148 148 149 149 unsigned int b0_bits; /* Data bits in first byte */ 150 150 unsigned int cbytes; /* Number of continuation bytes */ 151 151 152 152 if ((b0 & 0x80) == 0) { 153 153 /* 0xxxxxxx (Plain ASCII) */ … … 170 170 return U_SPECIAL; 171 171 } 172 172 173 173 if (*offset + cbytes > size) 174 174 return U_SPECIAL; 175 175 176 176 wchar_t ch = b0 & LO_MASK_8(b0_bits); 177 177 178 178 /* Decode continuation bytes */ 179 179 while (cbytes > 0) { 180 180 uint8_t b = (uint8_t) str[(*offset)++]; 181 181 182 182 /* Must be 10xxxxxx */ 183 183 if ((b & 0xc0) != 0x80) 184 184 return U_SPECIAL; 185 185 186 186 /* Shift data bits to ch */ 187 187 ch = (ch << CONT_BITS) | (wchar_t) (b & LO_MASK_8(CONT_BITS)); 188 188 cbytes--; 189 189 } 190 190 191 191 return ch; 192 192 } … … 211 211 if (*offset >= size) 212 212 return EOVERFLOW; 213 213 214 214 if (!chr_check(ch)) 215 215 return EINVAL; 216 216 217 217 /* Unsigned version of ch (bit operations should only be done 218 218 on unsigned types). */ 219 219 uint32_t cc = (uint32_t) ch; 220 220 221 221 /* Determine how many continuation bytes are needed */ 222 222 223 223 unsigned int b0_bits; /* Data bits in first byte */ 224 224 unsigned int cbytes; /* Number of continuation bytes */ 225 225 226 226 if ((cc & ~LO_MASK_32(7)) == 0) { 227 227 b0_bits = 7; … … 240 240 return EINVAL; 241 241 } 242 242 243 243 /* Check for available space in buffer */ 244 244 if (*offset + cbytes >= size) 245 245 return EOVERFLOW; 246 246 247 247 /* Encode continuation bytes */ 248 248 unsigned int i; … … 251 251 cc = cc >> CONT_BITS; 252 252 } 253 253 254 254 /* Encode first byte */ 255 255 str[*offset] = (cc & LO_MASK_32(b0_bits)) | HI_MASK_8(8 - b0_bits - 1); 256 256 257 257 /* Advance offset */ 258 258 *offset += cbytes + 1; 259 259 260 260 return EOK; 261 261 } … … 274 274 { 275 275 size_t size = 0; 276 276 277 277 while (*str++ != 0) 278 278 size++; 279 279 280 280 return size; 281 281 } … … 298 298 size_t len = 0; 299 299 size_t offset = 0; 300 300 301 301 while (len < max_len) { 302 302 if (str_decode(str, &offset, STR_NO_LIMIT) == 0) 303 303 break; 304 304 305 305 len++; 306 306 } 307 307 308 308 return offset; 309 309 } … … 320 320 size_t len = 0; 321 321 size_t offset = 0; 322 322 323 323 while (str_decode(str, &offset, STR_NO_LIMIT) != 0) 324 324 len++; 325 325 326 326 return len; 327 327 } … … 336 336 if (WCHAR_SIGNED_CHECK(ch >= 0) && (ch <= 127)) 337 337 return true; 338 338 339 339 return false; 340 340 } … … 349 349 if (WCHAR_SIGNED_CHECK(ch >= 0) && (ch <= 1114111)) 350 350 return true; 351 351 352 352 return false; 353 353 } … … 375 375 wchar_t c1 = 0; 376 376 wchar_t c2 = 0; 377 377 378 378 size_t off1 = 0; 379 379 size_t off2 = 0; 380 380 381 381 while (true) { 382 382 c1 = str_decode(s1, &off1, STR_NO_LIMIT); 383 383 c2 = str_decode(s2, &off2, STR_NO_LIMIT); 384 384 385 385 if (c1 < c2) 386 386 return -1; 387 387 388 388 if (c1 > c2) 389 389 return 1; 390 390 391 391 if ((c1 == 0) || (c2 == 0)) 392 392 break; 393 393 } 394 394 395 395 return 0; 396 396 } … … 412 412 size_t src_off = 0; 413 413 size_t dest_off = 0; 414 414 415 415 wchar_t ch; 416 416 while ((ch = str_decode(src, &src_off, STR_NO_LIMIT)) != 0) { … … 418 418 break; 419 419 } 420 420 421 421 dest[dest_off] = '\0'; 422 422 }
Note:
See TracChangeset
for help on using the changeset viewer.