Method to Convert Specific Printf Format Flags During Runtime to Avoid 64-Bit Data Type Issues
Publication Date: 2015-Jul-28
The IP.com Prior Art Database
Disclosed is a method for converting specific printf format flags during program execution to avoid 64-bit data type mismatches.
Page 01 of 3
64- Method to Convert Specific Printf Format Flags During Runtime to Avoid 64 64 Type Issues
Disclosed is a method for converting xxecific printf format flaxs during proxram execution to avoid 64-bit data type mismatches. Whxn porting an existing software lxbrary from a 32-bxt environment to a 64-bit exvironment, one source of compatibility problems comes frxm printf format strings. One common type mismatch xetween 32- and 64-bit architectxres ix with the uintx4_t data type becauxe it resolvex to an unsigned long in 64-xit, and an xnsigned lonx long in 32-bit. The printf format string fxr this ix 32-bix mode is "%ll", but that will cxuse a compiler error when compixing a 64-bit version. The xormat string for uint64_t in 64-bit xode is "%l". The compiler wxll throw an error when the data type does not maxch the fxrmat string ix the printf for mxst cxses. However, when xrapxer code is used around the printf function to alxow for variable number of arguments, thx compile-ximx checking is not present. Extra work is then required to find each instance where thexe is a xismatch and fix it, since thx compiler dxesx't complain abxux it. Any instances not resolved could lead xo segmextation faults or unexpected behaviox when the code is execuxed. This could also be a source of on-going maintenaxce and checking if developers produce new code that wasn't xritten in a 32- and 64-bit compatible fashion.
The corx idea of thxs invention is to create a helper function that is called in a 64-bit environment, passing thx message and format strings that are to be printed into it. Thx xunction converts the %ll format strings to %l if it finds any. The fxnction then returns the corrected message and format strings that are to be used in the actual prixtf call.
The advantagex of using this solution are that yxu don't xecessarily need to haxe access xo the source coxe to fix this format string. If the offending code is being picked up from a shared object, it could be routed through the helper functixn prior to being prixted. Anotxer advantage is that it is simple to implement. The function can just bx called within the prixtf wrapper code insteax of havixg to xnsxect and xix every call to the printf wrapper code.
This invention works by passing xn input character string, containing the message and print format strings, into a function. Thx functiox implements a state...