Skip to content

Convert IPaddress to string using a char array instead of a String#14

Merged
hirotakaster merged 3 commits intohirotakaster:masterfrom
alexmrqt:master
Mar 19, 2020
Merged

Convert IPaddress to string using a char array instead of a String#14
hirotakaster merged 3 commits intohirotakaster:masterfrom
alexmrqt:master

Conversation

@alexmrqt
Copy link
Copy Markdown

Any IPv4 address can be represented as a string between 16 (15 + '\0') and 8 (7 + '\0') characters :

  • 1.1.1.1 -> 7 + 1 characters.
  • 255.255.255.255 -> 15 + 1 characters.

Memory fragmentation due to String allocation can cause crash or undefined behaviors in microcontrollers. This is especially true for very constrained device like the atmega328p in the Arduino Uno.

This PR address this issue by changing the type of ipaddress to char[16], allowing for static memory allocation.
int -> string conversion is then handled by sprintf().

@alexmrqt
Copy link
Copy Markdown
Author

Note that this was also proposed in #5 :)

@hirotakaster hirotakaster merged commit 1fd104f into hirotakaster:master Mar 19, 2020
@hirotakaster
Copy link
Copy Markdown
Owner

@alexmrqt thank you for your pull request.

hirotakaster added a commit that referenced this pull request Mar 19, 2020
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.

2 participants