MCPcopy Create free account
hub / github.com/ValveSoftware/openvr / readChunk_tEXt

Function readChunk_tEXt

samples/shared/lodepng.cpp:4201–4241  ·  view source on GitHub ↗

text chunk (tEXt)*/

Source from the content-addressed store, hash-verified

4199
4200/*text chunk (tEXt)*/
4201static unsigned readChunk_tEXt(LodePNGInfo* info, const unsigned char* data, size_t chunkLength)
4202{
4203 unsigned error = 0;
4204 char *key = 0, *str = 0;
4205 unsigned i;
4206
4207 while(!error) /*not really a while loop, only used to break on error*/
4208 {
4209 unsigned length, string2_begin;
4210
4211 length = 0;
4212 while(length < chunkLength && data[length] != 0) length++;
4213 /*even though it's not allowed by the standard, no error is thrown if
4214 there's no null termination char, if the text is empty*/
4215 if(length < 1 || length > 79) CERROR_BREAK(error, 89); /*keyword too short or long*/
4216
4217 key = (char*)lodepng_malloc(length + 1);
4218 if(!key) CERROR_BREAK(error, 83); /*alloc fail*/
4219
4220 key[length] = 0;
4221 for(i = 0; i < length; i++) key[i] = (char)data[i];
4222
4223 string2_begin = length + 1; /*skip keyword null terminator*/
4224
4225 length = chunkLength < string2_begin ? 0 : (unsigned int)chunkLength - string2_begin;
4226 str = (char*)lodepng_malloc(length + 1);
4227 if(!str) CERROR_BREAK(error, 83); /*alloc fail*/
4228
4229 str[length] = 0;
4230 for(i = 0; i < length; i++) str[i] = (char)data[string2_begin + i];
4231
4232 error = lodepng_add_text(info, key, str);
4233
4234 break;
4235 }
4236
4237 lodepng_free(key);
4238 lodepng_free(str);
4239
4240 return error;
4241}
4242
4243/*compressed text chunk (zTXt)*/
4244static unsigned readChunk_zTXt(LodePNGInfo* info, const LodePNGDecompressSettings* zlibsettings,

Callers 1

decodeGenericFunction · 0.85

Calls 3

lodepng_mallocFunction · 0.85
lodepng_add_textFunction · 0.85
lodepng_freeFunction · 0.85

Tested by

no test coverage detected