-
Notifications
You must be signed in to change notification settings - Fork 217
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix up pointer subtraction (do not cast to integers) #142
Comments
Imported from trac issue 119. Created by glimes on 2015-11-20T14:49:27, last modified: 2015-12-09T11:13:56 |
Trac comment by glimes on 2015-11-30 15:20:49: I could have sworn I saw this sort of thing in several places, but the scan of the OSAL development tree today only picked up the three OS_check_name_length() implementations (posix, vxworks, rtems). Original code:
}}} Replacement code:
}}} In both cases, comments elided and braces minimized for brevity in this ticket. This change has been pushed to babelfish as [changeset:90d6145 changeset 90d6145: trac-119-bad-pointer-math] |
Trac comment by glimes on 2015-12-01 11:18:12: Ephemeral test links from last night (these go away soon): [https://babelfish.arc.nasa.gov/bamboo/browse/CFS-CFSOSAL54-241 OSAL ic-gll-merge results look good] [https://babelfish.arc.nasa.gov/bamboo/browse/CFS-CFSCFE47-78 CFE ic-gll-merge results look good] |
Trac comment by glimes on 2015-12-09 11:04:43: Commit [changeset:90d6145] included via merge [changeset:f3ebb35] into merge [changeset:961b061] which is now the development branch. |
Pointer subtraction works. Code that casts the pointers
into integer types differs from the correct code only in
its obfuscation.
Additionally, where pointer subtraction is used to determine
the length of a string, the entire sequence should be replaced
by a call to strlen().
On a side note, dividing by "sizeof(char)" is also mere obfuscation
as the standard defines that sizeof returns the size in (char) units.
Note that when attempting to compile for 64-bit targets, these will usually be flagged as "casting pointer to wrong sized integer" -- this may help to find problematic code.
Start with OS_check_name_length().
The text was updated successfully, but these errors were encountered: