RagePhoto.c: fix potential memory issue, fix debug code

This commit is contained in:
Syping 2023-06-06 21:05:55 +02:00
parent c3e838cecf
commit 6066d92ee9

View file

@ -504,29 +504,29 @@ bool ragephotodata_load(RagePhotoData *rp_data, RagePhotoFormatParser *rp_parser
} }
#ifdef RAGEPHOTO_DEBUG #ifdef RAGEPHOTO_DEBUG
std::cout << "header: " << rp_data->header << std::endl; printf("header: %s\n", rp_data->header);
std::cout << "headerSum: " << rp_data->headerSum << std::endl; printf("headerSum: %lu\n", rp_data->headerSum);
std::cout << "headerSum2: " << rp_data->headerSum2 << std::endl; printf("headerSum2: %lu\n", rp_data->headerSum2);
std::cout << "photoBuffer: " << rp_data->jpegBuffer << std::endl; printf("photoBuffer: %lu\n", rp_data->jpegBuffer);
std::cout << "descBuffer: " << rp_data->descBuffer << std::endl; printf("descBuffer: %lu\n", rp_data->descBuffer);
std::cout << "descOffset: " << rp_data->descOffset << std::endl; printf("descOffset: %lu\n", rp_data->descOffset);
std::cout << "description: " << rp_data->description << std::endl; printf("description: %s\n", rp_data->description);
std::cout << "jsonBuffer: " << rp_data->jsonBuffer << std::endl; printf("jsonBuffer: %lu\n", rp_data->jsonBuffer);
std::cout << "jsonOffset: " << rp_data->jsonOffset << std::endl; printf("jsonOffset: %lu\n", rp_data->jsonOffset);
std::cout << "json: " << rp_data->json << std::endl; printf("json: %s\n", rp_data->json);
std::cout << "sign: " << jpegSign(rp_data) << std::endl; printf("sign: %llu\n", ragephotodata_getphotosign(rp_data));
std::cout << "titlBuffer: " << rp_data->titlBuffer << std::endl; printf("titlBuffer: %lu\n", rp_data->titlBuffer);
std::cout << "titlOffset: " << rp_data->titlOffset << std::endl; printf("titlOffset: %lu\n", rp_data->titlOffset);
std::cout << "title: " << rp_data->title << std::endl; printf("title: %s\n", rp_data->title);
std::cout << "eofOffset: " << rp_data->endOfFile << std::endl; printf("eofOffset: %lu\n", rp_data->endOfFile);
std::cout << "setBufferOffsets()" << std::endl; printf("ragephotodata_setbufferoffsets()\n");
setBufferOffsets(rp_data); ragephotodata_setbufferoffsets(rp_data);
std::cout << "descOffset: " << rp_data->descOffset << std::endl; printf("descOffset: %lu\n", rp_data->descOffset);
std::cout << "jsonOffset: " << rp_data->jsonOffset << std::endl; printf("jsonOffset: %lu\n", rp_data->jsonOffset);
std::cout << "titlOffset: " << rp_data->titlOffset << std::endl; printf("titlOffset: %lu\n", rp_data->titlOffset);
std::cout << "eofOffset: " << rp_data->endOfFile << std::endl; printf("eofOffset: %lu\n", rp_data->endOfFile);
std::cout << "calc size: " << saveSize(rp_data, rp_parser) << std::endl; printf("calc size: %lu\n", ragephotodata_getsavesize(rp_data, rp_parser));
std::cout << "real size: " << length << std::endl; printf("real size: %lu\n", length);
#endif #endif
rp_data->error = RAGEPHOTO_ERROR_NOERROR; // 255 rp_data->error = RAGEPHOTO_ERROR_NOERROR; // 255
@ -912,6 +912,8 @@ bool ragephoto_savefilef(ragephoto_t instance_t, const char *filename, uint32_t
RagePhotoInstance *instance = (RagePhotoInstance*)instance_t; RagePhotoInstance *instance = (RagePhotoInstance*)instance_t;
const size_t fileSize = ragephotodata_getsavesizef(instance->data, instance->parser, photoFormat); const size_t fileSize = ragephotodata_getsavesizef(instance->data, instance->parser, photoFormat);
char *data = (char*)(malloc(fileSize)); char *data = (char*)(malloc(fileSize));
if (!data)
return false;
if (!ragephotodata_savef(instance->data, instance->parser, data, photoFormat)) { if (!ragephotodata_savef(instance->data, instance->parser, data, photoFormat)) {
free(data); free(data);
return false; return false;