text chunk (tEXt)*/
| 4300 | |
| 4301 | /*text chunk (tEXt)*/ |
| 4302 | static unsigned readChunk_tEXt(LodePNGInfo* info, const unsigned char* data, size_t chunkLength) |
| 4303 | { |
| 4304 | unsigned error = 0; |
| 4305 | char *key = 0, *str = 0; |
| 4306 | unsigned i; |
| 4307 | |
| 4308 | while(!error) /*not really a while loop, only used to break on error*/ |
| 4309 | { |
| 4310 | unsigned length, string2_begin; |
| 4311 | |
| 4312 | length = 0; |
| 4313 | while(length < chunkLength && data[length] != 0) ++length; |
| 4314 | /*even though it's not allowed by the standard, no error is thrown if |
| 4315 | there's no null termination char, if the text is empty*/ |
| 4316 | if(length < 1 || length > 79) CERROR_BREAK(error, 89); /*keyword too short or long*/ |
| 4317 | |
| 4318 | key = (char*)lodepng_malloc(length + 1); |
| 4319 | if(!key) CERROR_BREAK(error, 83); /*alloc fail*/ |
| 4320 | |
| 4321 | key[length] = 0; |
| 4322 | for(i = 0; i != length; ++i) key[i] = (char)data[i]; |
| 4323 | |
| 4324 | string2_begin = length + 1; /*skip keyword null terminator*/ |
| 4325 | |
| 4326 | length = chunkLength < string2_begin ? 0 : chunkLength - string2_begin; |
| 4327 | str = (char*)lodepng_malloc(length + 1); |
| 4328 | if(!str) CERROR_BREAK(error, 83); /*alloc fail*/ |
| 4329 | |
| 4330 | str[length] = 0; |
| 4331 | for(i = 0; i != length; ++i) str[i] = (char)data[string2_begin + i]; |
| 4332 | |
| 4333 | error = lodepng_add_text(info, key, str); |
| 4334 | |
| 4335 | break; |
| 4336 | } |
| 4337 | |
| 4338 | lodepng_free(key); |
| 4339 | lodepng_free(str); |
| 4340 | |
| 4341 | return error; |
| 4342 | } |
| 4343 | |
| 4344 | /*compressed text chunk (zTXt)*/ |
| 4345 | static unsigned readChunk_zTXt(LodePNGInfo* info, const LodePNGDecompressSettings* zlibsettings, |
no test coverage detected