code: drawterm

Download patch

ref: e56902a661c4c62e04596b3c2c58e43ed8328590
parent: 3c6be4750088503e4387a3b3b4910354c89913ed
author: cinap_lenrek <cinap_lenrek@felloff.net>
date: Sat Jan 11 19:16:07 EST 2020

devdraw: fix topnwindows() panic when images are not windows (thanks aiju)

Crashes drawterm and native:

#include <u.h>
#include <libc.h>
#include <draw.h>

void
main(int argc, char **argv)
{
 	initdraw(nil, nil, nil);

 	Image *a[] = {screen, display->black};

 	topnwindows(a, nelem(a));
 	flushimage(display, 1);
}

--- a/kern/devdraw.c
+++ b/kern/devdraw.c
@@ -2023,13 +2023,13 @@
 				free(lp);
 				nexterror();
 			}
-			for(j=0; j<nw; j++)
+			for(j=0; j<nw; j++){
 				lp[j] = drawimage(client, a+1+1+2+j*4);
-			if(lp[0]->layer == 0)
-				error("images are not windows");
-			for(j=1; j<nw; j++)
+				if(lp[j]->layer == 0)
+					error("images are not windows");
 				if(lp[j]->layer->screen != lp[0]->layer->screen)
 					error("images not on same screen");
+			}
 			if(a[1])
 				memltofrontn(lp, nw);
 			else