From 993f77d2a6643ae11eec4de238816ae5612b8dde Mon Sep 17 00:00:00 2001 From: sean Date: Mon, 21 Apr 2025 20:00:31 +0200 Subject: [PATCH] Make IPAddress operators use size_t and always return references --- teensy/IPAddress.h | 4 ++-- teensy3/IPAddress.h | 8 ++++---- teensy4/IPAddress.h | 8 ++++---- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/teensy/IPAddress.h b/teensy/IPAddress.h index 3640f5639..4afc62e3f 100644 --- a/teensy/IPAddress.h +++ b/teensy/IPAddress.h @@ -63,8 +63,8 @@ class IPAddress : public Printable { bool operator==(const uint8_t* addr); // Overloaded index operator to allow getting and setting individual octets of the address - uint8_t operator[](int index) const { return _address.bytes[index]; }; - uint8_t& operator[](int index) { return _address.bytes[index]; }; + uint8_t& operator[](const size_t index) { return _address.bytes[index]; } + const uint8_t& operator[](const size_t index) const { return _address.bytes[index]; } // Overloaded copy operators to allow initialisation of IPAddress objects from other types IPAddress& operator=(const uint8_t *address); diff --git a/teensy3/IPAddress.h b/teensy3/IPAddress.h index c71ea0427..4631593d7 100644 --- a/teensy3/IPAddress.h +++ b/teensy3/IPAddress.h @@ -94,12 +94,12 @@ class IPAddress : public Printable { } // Overloaded index operator to allow getting and setting individual octets of the address - uint8_t operator[](int index) const { + uint8_t& operator[](const size_t index) { return _address.bytes[index]; - }; - uint8_t& operator[](int index) { + } + const uint8_t& operator[](const size_t index) const { return _address.bytes[index]; - }; + } // Overloaded copy operators to allow initialisation of IPAddress objects from other types IPAddress& operator=(const uint8_t *address) { diff --git a/teensy4/IPAddress.h b/teensy4/IPAddress.h index c71ea0427..4631593d7 100644 --- a/teensy4/IPAddress.h +++ b/teensy4/IPAddress.h @@ -94,12 +94,12 @@ class IPAddress : public Printable { } // Overloaded index operator to allow getting and setting individual octets of the address - uint8_t operator[](int index) const { + uint8_t& operator[](const size_t index) { return _address.bytes[index]; - }; - uint8_t& operator[](int index) { + } + const uint8_t& operator[](const size_t index) const { return _address.bytes[index]; - }; + } // Overloaded copy operators to allow initialisation of IPAddress objects from other types IPAddress& operator=(const uint8_t *address) {