tracker issue : CF-3830777

select a category, or use search below
(searches all categories and all time range)
Title:

Allow lengths of 32 bits for the BitMask* family of functions

| View in Tracker

Status/Resolution/Reason: Closed/Withdrawn/DesignLimitation

Reporter/Name(from Bugbase): Chris Bouchard / Chris Bouchard (javajunkie314)

Created: 09/23/2014

Components: Language

Versions: 11.0

Failure Type: Enhancement Request

Found In Build/Fixed In Build: CF11_Final /

Priority/Frequency: Minor / Some users will encounter

Locale/System: ALL / Platforms All

Vote Count: 0

Problem Description:
The bitmasking functions all take start and length parameters, which limit the bits to be affected by the masking operation. The start index must be between 0 and 31 inclusive, which makes sense as it represents a bit index. The length parameter must also be between 0 and 31 inclusive, which makes less sense.

There does not seem to be any particular reason to disallow a length of 32, and allowing it would prevent a potential class of bugs. For example, when converting a CIDR address to an IP address and netmask, it is tempting to write the following:

    netmask = BitMaskClear(-1, 0, (32 - maskLen))

However, when maskLen is 0, this code will throw an exception rather than producing the expected netmask of 0. This behavior is unintuitive, since the result would be well-defined if we used BitAnd directly.

Steps to Reproduce:

1. Pass a length of 32 to a bitmask function, e.g., BitMaskClear(-1, 0, 32)

Actual Result:

The function call produces an invalid argument exception.

Expected Result:

The function call returns the value 0, which should be the result of clearing all 32 bits of a 32-bit integer.

Any Workarounds:

Each call to a bitmasking functions can be wrapped in an if statement that checks if the length is 32 and if so computes the correct result. For BitMaskClear, it should always return 0. For BitMaskSet, it should call BitOr instead. For BitMaskRead, it should return the number unchanged.

----------------------------- Additional Watson Details -----------------------------

Watson Bug ID:	3830777

External Customer Info:
External Company:  
External Customer Name: javajunkie314
External Customer Email:  
External Test Config: My Hardware and Environment details:

I tested this in ColdFusion 11 on Mac OS X 10.9.4.

Attachments:

Comments:

javajunkie314, Length of 32 is not allowed for bitwise operations for the reason mentioned here: http://docs.oracle.com/javase/specs/jls/se8/html/jls-15.html#jls-15.19
Comment by Piyush K.
10834 | July 07, 2015 11:58:41 PM GMT