MCPcopy Create free account
hub / github.com/DFHack/dfhack / readChunk_tEXt

Function readChunk_tEXt

depends/lodepng/lodepng.cpp:4431–4468  ·  view source on GitHub ↗

text chunk (tEXt)*/

Source from the content-addressed store, hash-verified

4429
4430/*text chunk (tEXt)*/
4431static unsigned readChunk_tEXt(LodePNGInfo* info, const unsigned char* data, size_t chunkLength) {
4432 unsigned error = 0;
4433 char *key = 0, *str = 0;
4434
4435 while(!error) /*not really a while loop, only used to break on error*/ {
4436 unsigned length, string2_begin;
4437
4438 length = 0;
4439 while(length < chunkLength && data[length] != 0) ++length;
4440 /*even though it's not allowed by the standard, no error is thrown if
4441 there's no null termination char, if the text is empty*/
4442 if(length < 1 || length > 79) CERROR_BREAK(error, 89); /*keyword too short or long*/
4443
4444 key = (char*)lodepng_malloc(length + 1);
4445 if(!key) CERROR_BREAK(error, 83); /*alloc fail*/
4446
4447 lodepng_memcpy(key, data, length);
4448 key[length] = 0;
4449
4450 string2_begin = length + 1; /*skip keyword null terminator*/
4451
4452 length = (unsigned)(chunkLength < string2_begin ? 0 : chunkLength - string2_begin);
4453 str = (char*)lodepng_malloc(length + 1);
4454 if(!str) CERROR_BREAK(error, 83); /*alloc fail*/
4455
4456 lodepng_memcpy(str, data + string2_begin, length);
4457 str[length] = 0;
4458
4459 error = lodepng_add_text(info, key, str);
4460
4461 break;
4462 }
4463
4464 lodepng_free(key);
4465 lodepng_free(str);
4466
4467 return error;
4468}
4469
4470/*compressed text chunk (zTXt)*/
4471static unsigned readChunk_zTXt(LodePNGInfo* info, const LodePNGDecoderSettings* decoder,

Callers 2

lodepng_inspect_chunkFunction · 0.85
decodeGenericFunction · 0.85

Calls 4

lodepng_mallocFunction · 0.85
lodepng_memcpyFunction · 0.85
lodepng_add_textFunction · 0.85
lodepng_freeFunction · 0.85

Tested by

no test coverage detected