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

Casting pointers to int is dangerous #3

Open
brewmanz opened this issue Jun 7, 2022 · 1 comment
Open

Casting pointers to int is dangerous #3

brewmanz opened this issue Jun 7, 2022 · 1 comment

Comments

@brewmanz
Copy link

brewmanz commented Jun 7, 2022

A couple of times in dump.cpp (and maybe elsewhere; I didn't check further) you cast a pointer to an int.

 void *memAddress = (void *)((int)at + c);
 at = (void *)((int)at + 1);

This is dangerous, as, with some combination of hardware and software, that can result in a 4 or 8 byte pointer being cast to a 2 or 4 byte integer.
I suggest using size_t instead as

  • It's unsigned
  • It's guaranteed to be large enough to store a pointer

Examples where there are problems:

  • EpoxyDuino, where sizeof(int) is 4 and sizeof(void*) is 8.
  • I expect similar with Arduino Mega with 256K Flash; I expect 4 byte pointer and 2 byte integer, but I haven't checked this.

On other occasions, you cast pointers as unsigned long e.g. out.print((unsigned long)at,HEX);. consider changing these to size_t also, to save space on typical Arduinos (Uno & Nano, anyway).

@neu-rah
Copy link
Owner

neu-rah commented Aug 4, 2022

indeed, thanks. A pull request would be wonderful :D
any1?

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

No branches or pull requests

2 participants