Make operation reversable

Before didn't write the final IEND chunk
This commit is contained in:
Isaac Shoebottom 2023-12-04 20:29:04 -04:00
parent 0a18d16eb0
commit 73234d0764

View File

@ -126,7 +126,7 @@ int get_number_of_chunks(png_chunk **chunks) {
while (memcmp(chunks[i]->type, "IEND", 4) != 0) {
i++;
}
return i;
return ++i;
}
void xor_data(png_chunk *chunk) {
@ -139,8 +139,7 @@ void xor_data(png_chunk *chunk) {
void destroy_chunks(png_chunk **chunks) {
unsigned int size = get_number_of_chunks(chunks);
// +1 for IEND chunk
for (int i = 0; i < size + 1; i++) {
for (int i = 0; i < size; i++) {
free(chunks[i]->data);
free(chunks[i]);
}