Commits

Anonymous committed 77df5ef

replace pow(2, ) with a bitwise shift
add comment to note that no overflow check is necessary in the colorMap* allocations

  • Participants
  • Parent commits afa1ba4
  • Branches GD-2.0

Comments (0)

Files changed (1)

File src/gd_tiff.c

 
 	/* build the color map for 8 bit images */
 	if(bitDepth != 24) {
-		/*TODO: Add checking */
-		colorMapRed = (uint16 *) gdMalloc(3 * pow(2, bitsPerSample));
-		colorMapGreen = (uint16 *) gdMalloc(3 * pow(2, bitsPerSample));
-		colorMapBlue = (uint16 *) gdMalloc(3 * pow(2, bitsPerSample));
+		/* no overflow check is necessary because bitsPerSample is at most 8 and the following doesn't overflow */
+		colorMapRed = (uint16 *) gdMalloc(3 * (1 << bitsPerSample));
+		colorMapGreen = (uint16 *) gdMalloc(3 * (1 << bitsPerSample));
+		colorMapBlue = (uint16 *) gdMalloc(3 * (1 << bitsPerSample));
 
 		for(i = 0; i < image->colorsTotal; i++) {
 			colorMapRed[i] = gdImageRed(image,i) + (gdImageRed(image,i) * 256);
 	uint32 offset;
 
 	TIFFGetField(tiff, TIFFTAG_BITSPERSAMPLE, &bitsPerSample);
-	offset = pow(2, bitsPerSample);
+	offset = 1 << bitsPerSample;
 
 	if(color == 0) {
 		val = ctx.red[index];