-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Resolve MSVC C4244 level 2 warnings #17076
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1134,7 +1134,7 @@ void gdImageLine (gdImagePtr im, int x1, int y1, int x2, int y2, int color) | |
TBB: but watch out for /0! */ | ||
double ac = cos (atan2 (dy, dx)); | ||
if (ac != 0) { | ||
wid = thick / ac; | ||
wid = (int) (thick / ac); | ||
} else { | ||
wid = 1; | ||
} | ||
|
@@ -1198,7 +1198,7 @@ TBB: but watch out for /0! */ | |
TBB: but watch out for /0! */ | ||
double as = sin (atan2 (dy, dx)); | ||
if (as != 0) { | ||
wid = thick / as; | ||
wid = (int) (thick / as); | ||
} else { | ||
wid = 1; | ||
} | ||
|
@@ -1388,7 +1388,7 @@ void gdImageDashedLine (gdImagePtr im, int x1, int y1, int x2, int y2, int color | |
TBB: but watch out for /0! */ | ||
double as = sin(atan2(dy, dx)); | ||
if (as != 0) { | ||
wid = thick / as; | ||
wid = (int) (thick / as); | ||
} else { | ||
wid = 1; | ||
} | ||
|
@@ -1437,7 +1437,7 @@ void gdImageDashedLine (gdImagePtr im, int x1, int y1, int x2, int y2, int color | |
TBB: but watch out for /0! */ | ||
double as = sin (atan2 (dy, dx)); | ||
if (as != 0) { | ||
wid = thick / as; | ||
wid = (int) (thick / as); | ||
} else { | ||
wid = 1; | ||
} | ||
|
@@ -2827,7 +2827,7 @@ void gdImageFilledPolygon (gdImagePtr im, gdPointPtr p, int n, int c) | |
* same footprint. | ||
*/ | ||
if (y >= y1 && y < y2) { | ||
im->polyInts[ints++] = (float) ((y - y1) * (x2 - x1)) / (float) (y2 - y1) + 0.5 + x1; | ||
im->polyInts[ints++] = (int) ((float) ((y - y1) * (x2 - x1)) / (float) (y2 - y1) + 0.5 + x1); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This one is okay. |
||
} else if (y == pmaxy && y == y2) { | ||
im->polyInts[ints++] = x2; | ||
} | ||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -81,7 +81,7 @@ static int quality2Quantizer(int quality) { | |||||
|
||||||
float scaleFactor = (float) AVIF_QUANTIZER_WORST_QUALITY / (float) MAX_QUALITY; | ||||||
|
||||||
return round(scaleFactor * (MAX_QUALITY - clampedQuality)); | ||||||
return (int) round(scaleFactor * (MAX_QUALITY - clampedQuality)); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think the float calculation is unnecessary here. The following should be good enough:
Suggested change
But changing this now would introduce a subtle BC break, so just casting to int appears to be sensible for now. |
||||||
} | ||||||
|
||||||
/* | ||||||
|
@@ -103,7 +103,7 @@ static avifBool setEncoderTilesAndThreads(avifEncoder *encoder, avifRGBImage *rg | |||||
|
||||||
// The number of tiles in any dimension will always be a power of 2. We can only specify log(2)tiles. | ||||||
|
||||||
tilesLog2 = floor(log2(tiles)); | ||||||
tilesLog2 = (int) floor(log2(tiles)); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why do we even
Suggested change
And given we're interested in the log2 of an integer, there are even options not requiring an FP instruction (especially since tiles <= 8). But okay. |
||||||
|
||||||
// If the image's width is greater than the height, use more tile columns | ||||||
// than tile rows to make the tile size close to a square. | ||||||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -2137,8 +2137,7 @@ gdImagePtr gdImageRotateInterpolated(const gdImagePtr src, const float angle, in | |||||
/* round to two decimals and keep the 100x multiplication to use it in the common square angles | ||||||
case later. Keep the two decimal precisions so smaller rotation steps can be done, useful for | ||||||
slow animations. */ | ||||||
const int angle_rounded = fmod((int) floorf(angle * 100), 360 * 100); | ||||||
|
||||||
const int angle_rounded = (int) fmod((int) floorf(angle * 100), 360 * 100); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This looks seriously overengineered. Why are there even float operations, instead of
Suggested change
|
||||||
if (bgcolor < 0) { | ||||||
return NULL; | ||||||
} | ||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -156,7 +156,7 @@ void gdImageWebpCtx (gdImagePtr im, gdIOCtx * outfile, int quality) | |
if (quality >= gdWebpLossless) { | ||
out_size = WebPEncodeLosslessRGBA(argb, gdImageSX(im), gdImageSY(im), gdImageSX(im) * 4, &out); | ||
} else { | ||
out_size = WebPEncodeRGBA(argb, gdImageSX(im), gdImageSY(im), gdImageSX(im) * 4, quality, &out); | ||
out_size = WebPEncodeRGBA(argb, gdImageSX(im), gdImageSY(im), gdImageSX(im) * 4, (float) quality, &out); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The simple cast is fine here to suppress the warning. ext/gd catches values < -1 early, and for libgd, such values cause |
||
} | ||
|
||
if (out_size == 0) { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -473,7 +473,7 @@ PHPAPI zend_long php_mt_rand_common(zend_long min, zend_long max) | |
/* This is an inlined version of the RAND_RANGE_BADSCALING macro that does not invoke UB when encountering | ||
* (max - min) > ZEND_LONG_MAX. | ||
*/ | ||
zend_ulong offset = (double) ( (double) max - min + 1.0) * (r / (PHP_MT_RAND_MAX + 1.0)); | ||
zend_ulong offset = (zend_ulong) (((double) max - min + 1.0) * (r / (PHP_MT_RAND_MAX + 1.0))); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The old version appears to "over-cast", so I simplified. @TimWolla, @zeriyoshi, thoughts? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. looks good! |
||
|
||
return (zend_long) (offset + min); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems to me that rounding would make sense here, but likely introduces a subtle BC break; as such casting to int is okay.