diff options
-rw-r--r-- | src/Xcup.c | 25 |
1 files changed, 11 insertions, 14 deletions
@@ -219,24 +219,21 @@ XcupStoreColors( } if (_XReply(dpy, (xReply *)&rep, 0, xFalse)) { - long nbytes; + unsigned long nbytes; xColorItem* rbufp; xColorItem* cs; - int nentries = rep.length / 3; - - nbytes = nentries * SIZEOF (xColorItem); + unsigned int nentries = rep.length / 3; - if (nentries != ncolors) { - _XEatDataWords(dpy, rep.length); - UnlockDisplay (dpy); - SyncHandle (); - return False; - } + if ((nentries == ncolors) && + (nentries < (INT_MAX / SIZEOF (xColorItem)))) { + nbytes = nentries * SIZEOF (xColorItem); - if (ncolors > 256) - rbufp = (xColorItem*) Xmalloc (nbytes); - else - rbufp = rbuf; + if (ncolors > 256) + rbufp = Xmalloc (nbytes); + else + rbufp = rbuf; + } else + rbufp = NULL; if (rbufp == NULL) { _XEatDataWords(dpy, rep.length); |