Skip to content
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

Protect illegal access on types.h floats #8820

Merged

Conversation

Nir-Az
Copy link
Collaborator

@Nir-Az Nir-Az commented Apr 13, 2021

Fix CppCheck warning on types.h

i.e:
src\types.h:585:24: warning: The address of local variable 'x' might be accessed at non-zero index. [objectIndex]
return (&x)[i];

@Nir-Az Nir-Az changed the title Protect illegal access to types.h floats Protect illegal access on types.h floats Apr 13, 2021
ev-mp
ev-mp previously requested changes Apr 13, 2021
src/types.h Outdated Show resolved Hide resolved
src/types.h Outdated Show resolved Hide resolved
common/viewer.cpp Outdated Show resolved Hide resolved
@ev-mp
Copy link
Collaborator

ev-mp commented Apr 20, 2021

The issue remains as in release the code compiles and runs unchecked.

#include <iostream>

int main() {
	// your code goes here
	struct float2 { float x, y; float & operator [] (int i) { return (&x)[i]; } };
	float2 f{1,2};
	for (int i=0; i<=2; i++)
	    std::cout << "f[" << i << "] = " << f[i];
	return 0;
}

f[0] = 1f[1] = 2f[2] = 1.07638e-32

@Nir-Az
Copy link
Collaborator Author

Nir-Az commented Apr 20, 2021

The issue remains as in release the code compiles and runs unchecked.

#include <iostream>

int main() {
	// your code goes here
	struct float2 { float x, y; float & operator [] (int i) { return (&x)[i]; } };
	float2 f{1,2};
	for (int i=0; i<=2; i++)
	    std::cout << "f[" << i << "] = " << f[i];
	return 0;
}

f[0] = 1f[1] = 2f[2] = 1.07638e-32

Correct, as discussed the fix protect only debug configuration, please speak with @maloel if you think release should be protected too.

@maloel maloel dismissed ev-mp’s stale review April 20, 2021 11:06

The purpose of this PR is to remove CppCheck warnings; asserts are acceptable for now

@maloel maloel merged commit eb2448e into IntelRealSense:development Apr 20, 2021
@Nir-Az Nir-Az deleted the fix_cppcheck_error_on_types.h branch July 27, 2021 12:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants