Skip to content

Commit 05fcb65

Browse files
authored
Merge pull request numpy#19951 from DimitriPapadopoulos/lgtm_warning_sizeof_Dragon4_Scratch_repr
MAINT: Fix LGTM.com warning: Comparison is always false because `bufferSize` >= 16384
2 parents 7b22284 + cfadd9f commit 05fcb65

File tree

1 file changed

+6
-59
lines changed

1 file changed

+6
-59
lines changed

numpy/core/src/multiarray/dragon4.c

Lines changed: 6 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -2206,7 +2206,7 @@ Dragon4_PrintFloat_IEEE_binary16(
22062206
Dragon4_Scratch *scratch, npy_half *value, Dragon4_Options *opt)
22072207
{
22082208
char *buffer = scratch->repr;
2209-
npy_uint32 bufferSize = sizeof(scratch->repr);
2209+
const npy_uint32 bufferSize = sizeof(scratch->repr);
22102210
BigInt *bigints = scratch->bigints;
22112211

22122212
npy_uint16 val = *value;
@@ -2218,15 +2218,6 @@ Dragon4_PrintFloat_IEEE_binary16(
22182218
npy_bool hasUnequalMargins;
22192219
char signbit = '\0';
22202220

2221-
if (bufferSize == 0) {
2222-
return 0;
2223-
}
2224-
2225-
if (bufferSize == 1) {
2226-
buffer[0] = '\0';
2227-
return 0;
2228-
}
2229-
22302221
/* deconstruct the floating point value */
22312222
floatMantissa = val & bitmask_u32(10);
22322223
floatExponent = (val >> 10) & bitmask_u32(5);
@@ -2303,7 +2294,7 @@ Dragon4_PrintFloat_IEEE_binary32(
23032294
Dragon4_Options *opt)
23042295
{
23052296
char *buffer = scratch->repr;
2306-
npy_uint32 bufferSize = sizeof(scratch->repr);
2297+
const npy_uint32 bufferSize = sizeof(scratch->repr);
23072298
BigInt *bigints = scratch->bigints;
23082299

23092300
union
@@ -2319,15 +2310,6 @@ Dragon4_PrintFloat_IEEE_binary32(
23192310
npy_bool hasUnequalMargins;
23202311
char signbit = '\0';
23212312

2322-
if (bufferSize == 0) {
2323-
return 0;
2324-
}
2325-
2326-
if (bufferSize == 1) {
2327-
buffer[0] = '\0';
2328-
return 0;
2329-
}
2330-
23312313
/* deconstruct the floating point value */
23322314
floatUnion.floatingPoint = *value;
23332315
floatMantissa = floatUnion.integer & bitmask_u32(23);
@@ -2404,7 +2386,7 @@ Dragon4_PrintFloat_IEEE_binary64(
24042386
Dragon4_Scratch *scratch, npy_float64 *value, Dragon4_Options *opt)
24052387
{
24062388
char *buffer = scratch->repr;
2407-
npy_uint32 bufferSize = sizeof(scratch->repr);
2389+
const npy_uint32 bufferSize = sizeof(scratch->repr);
24082390
BigInt *bigints = scratch->bigints;
24092391

24102392
union
@@ -2421,14 +2403,6 @@ Dragon4_PrintFloat_IEEE_binary64(
24212403
npy_bool hasUnequalMargins;
24222404
char signbit = '\0';
24232405

2424-
if (bufferSize == 0) {
2425-
return 0;
2426-
}
2427-
2428-
if (bufferSize == 1) {
2429-
buffer[0] = '\0';
2430-
return 0;
2431-
}
24322406

24332407
/* deconstruct the floating point value */
24342408
floatUnion.floatingPoint = *value;
@@ -2527,7 +2501,7 @@ Dragon4_PrintFloat_Intel_extended(
25272501
Dragon4_Scratch *scratch, FloatVal128 value, Dragon4_Options *opt)
25282502
{
25292503
char *buffer = scratch->repr;
2530-
npy_uint32 bufferSize = sizeof(scratch->repr);
2504+
const npy_uint32 bufferSize = sizeof(scratch->repr);
25312505
BigInt *bigints = scratch->bigints;
25322506

25332507
npy_uint32 floatExponent, floatSign;
@@ -2539,15 +2513,6 @@ Dragon4_PrintFloat_Intel_extended(
25392513
npy_bool hasUnequalMargins;
25402514
char signbit = '\0';
25412515

2542-
if (bufferSize == 0) {
2543-
return 0;
2544-
}
2545-
2546-
if (bufferSize == 1) {
2547-
buffer[0] = '\0';
2548-
return 0;
2549-
}
2550-
25512516
/* deconstruct the floating point value (we ignore the intbit) */
25522517
floatMantissa = value.lo & bitmask_u64(63);
25532518
floatExponent = value.hi & bitmask_u32(15);
@@ -2748,7 +2713,7 @@ Dragon4_PrintFloat_IEEE_binary128(
27482713
Dragon4_Scratch *scratch, FloatVal128 val128, Dragon4_Options *opt)
27492714
{
27502715
char *buffer = scratch->repr;
2751-
npy_uint32 bufferSize = sizeof(scratch->repr);
2716+
const npy_uint32 bufferSize = sizeof(scratch->repr);
27522717
BigInt *bigints = scratch->bigints;
27532718

27542719
npy_uint32 floatExponent, floatSign;
@@ -2759,15 +2724,6 @@ Dragon4_PrintFloat_IEEE_binary128(
27592724
npy_bool hasUnequalMargins;
27602725
char signbit = '\0';
27612726

2762-
if (bufferSize == 0) {
2763-
return 0;
2764-
}
2765-
2766-
if (bufferSize == 1) {
2767-
buffer[0] = '\0';
2768-
return 0;
2769-
}
2770-
27712727
mantissa_hi = val128.hi & bitmask_u64(48);
27722728
mantissa_lo = val128.lo;
27732729
floatExponent = (val128.hi >> 48) & bitmask_u32(15);
@@ -2917,7 +2873,7 @@ Dragon4_PrintFloat_IBM_double_double(
29172873
Dragon4_Scratch *scratch, npy_float128 *value, Dragon4_Options *opt)
29182874
{
29192875
char *buffer = scratch->repr;
2920-
npy_uint32 bufferSize = sizeof(scratch->repr);
2876+
const npy_uint32 bufferSize = sizeof(scratch->repr);
29212877
BigInt *bigints = scratch->bigints;
29222878

29232879
FloatVal128 val128;
@@ -2934,15 +2890,6 @@ Dragon4_PrintFloat_IBM_double_double(
29342890
npy_bool hasUnequalMargins;
29352891
char signbit = '\0';
29362892

2937-
if (bufferSize == 0) {
2938-
return 0;
2939-
}
2940-
2941-
if (bufferSize == 1) {
2942-
buffer[0] = '\0';
2943-
return 0;
2944-
}
2945-
29462893
/* The high part always comes before the low part, regardless of the
29472894
* endianness of the system. */
29482895
buf128.floatingPoint = *value;

0 commit comments

Comments
 (0)