Browse Prior Art Database

Character Numeric Overflow Checking in a Multithread Environment

IP.com Disclosure Number: IPCOM000113265D
Original Publication Date: 1994-Jul-01
Included in the Prior Art Database: 2005-Mar-27
Document File: 2 page(s) / 67K

Publishing Venue

IBM

Related People

Morgan, SA: AUTHOR

Abstract

All applications that require input from the user must perform data qualification when reading user input data. For numeric data being entered as characters, the application must translate this data into its numeric equivalent in order for it to be used.

This text was extracted from an ASCII text file.
This is the abbreviated version, containing approximately 52% of the total text.

Character Numeric Overflow Checking in a Multithread Environment

      All applications that require input from the user must perform
data qualification when reading user input data.  For numeric data
being entered as characters, the application must translate this data
into its numeric equivalent in order for it to be used.

      This is a straightforward conversion except for the problem
that the numeric value of the entered character data might overflow
the precision of the target storage variable.  For example, if the
string "32769" is converted to its numeric value and stored in a
signed integer variable (where an integer is represented as two bytes
of storage), an overflow will result and the stored number will be
perceived as being negative.  This type of error is possible for both
signed and unsigned numbers.

      The 16-bit IBM C/2* compiler sets a global variable that can be
tested after a conversion using one of the C-library functions such
as atoi to see if just such an overflow has occurred.  However, this
is unreliable in a multithread application because the global
variable set by the C-library function is not semaphore protected.
Due to thread switching in OS/2*, the thread that just performed the
conversion and caused the global variable to be set could be switched
away from before the code could check the global variable's value.
During the interval until this thread again gets control, another
thread could perform an operation that sets that same global variable
to another value.

      Using the C-library global variable to detect overflows is
therefore not reliable in a multithread application.  This disclosure
describes a technique that will overcome this shortcoming in the
C-library routines and ensure that overflows are detected and
...