Closed Bug 86125 Opened 23 years ago Closed 23 years ago

Unnecessary #if in mpi.c that breaks C preprocessors that don't understand LL constants

Categories

(NSS :: Libraries, defect, P2)

3.2.1
defect

Tracking

(Not tracked)

RESOLVED FIXED

People

(Reporter: wtc, Assigned: wtc)

References

Details

In mpi.c, we have the following:

#if DIGIT_MAX < 256
    if((res = s_mp_lshd(mp, 1)) != MP_OKAY)
      return res;
#else
    if((res = mp_mul_d(mp, 256, mp)) != MP_OKAY)
      return res;
#endif

On some platforms, mp_digit is an unsigned long long,
and DIGIT_MAX is a ULL constant.  This breaks some C
preprocessors that don't recognize long longs even
though the C compilers have no problem with them.

Looking at the code, I found that MP_DIGIT_MAX
(which DIGIT_MAX is a synonym for) is ULONG_MAX,
MP_ULONG_LONG_MAX, or UINT_MAX.  So it is at
least UINT_MAX.  Since C requires that int be
at least 16 bit long, UINT_MAX is greater than 256.
So #if DIGIT_MAX < 256 is always false.  Nelson,
is my reasoning correct?

This is my proposed patch.
Index: mpi.c
===================================================================
RCS file: /cvsroot/mozilla/security/nss/lib/freebl/mpi/mpi.c,v
retrieving revision 1.34
diff -u -r1.34 mpi.c
--- mpi.c       2001/05/31 00:12:18     1.34
+++ mpi.c       2001/06/15 19:03:02
@@ -2453,13 +2453,8 @@
 
   /* Read the rest of the digits */
   for(ix = 1; ix < len; ix++) {
-#if DIGIT_MAX < 256
-    if((res = s_mp_lshd(mp, 1)) != MP_OKAY)
-      return res;
-#else
     if((res = mp_mul_d(mp, 256, mp)) != MP_OKAY)
       return res;
-#endif
     if((res = mp_add_d(mp, ustr[ix], mp)) != MP_OKAY)
       return res;
   }
Priority: -- → P2
Target Milestone: --- → 3.3
This patch is fine with me.
I checked in the patch on the trunk of NSS.
Status: NEW → RESOLVED
Closed: 23 years ago
Resolution: --- → FIXED
Blocks: 86054
You need to log in before you can comment on or make changes to this bug.