git: 9front

Download patch

ref: d742ca0d6e78c9a0b6cf3baec1832f8c4ddc21e0
parent: f44ae2dc9f46a7055bfcc3400c563b1ae8c4d901
author: ppatience0 <ppatience0@gmail.com>
date: Sat Jun 1 13:14:50 EDT 2013

readgif, readjpg: fix incorrect malloc arguments: use sizeof(Rawimage*) instead of sizeof(Rawimage**) and 2*sizeof(Rawimage*) instead of sizeof(Header)

readtga: switch calloc arguments: nelem is supposed to first, elsize second

--- a/sys/src/cmd/jpg/readgif.c
+++ b/sys/src/cmd/jpg/readgif.c
@@ -156,7 +156,7 @@
 
 	if(h->fields & 0x80)
 		h->globalcmap = readcmap(h, (h->fields&7)+1);
-	array = malloc(sizeof(Rawimage**));
+	array = malloc(sizeof(Rawimage*));
 	if(array == nil)
 		giferror(h, memerr);
 	nimages = 0;
--- a/sys/src/cmd/jpg/readjpg.c
+++ b/sys/src/cmd/jpg/readjpg.c
@@ -247,7 +247,7 @@
 	}
 	jpginit();
 	h = malloc(sizeof(Header));
-	array = malloc(sizeof(Header));
+	array = malloc(2*sizeof(Rawimage*));
 	if(h==nil || array==nil){
 		free(h);
 		free(array);
--- a/sys/src/cmd/jpg/readtga.c
+++ b/sys/src/cmd/jpg/readtga.c
@@ -404,12 +404,12 @@
 	}
 
 	array = nil;
-	if((ar = calloc(sizeof(Rawimage), 1)) == nil){
+	if((ar = calloc(1, sizeof(Rawimage))) == nil){
 		werrstr("ReadTGA: no memory - %r\n");
 		goto Error;
 	}
 
-	if((array = calloc(sizeof(Rawimage *), 2)) == nil){
+	if((array = calloc(2, sizeof(Rawimage *))) == nil){
 		werrstr("ReadTGA: no memory - %r\n");
 		goto Error;
 	}
--