From bdf3baa8ac76ebdabd7826a8453fefe07f3f9dc9 Mon Sep 17 00:00:00 2001 From: Lenny Maiorani Date: Mon, 16 Nov 2020 17:41:46 -0700 Subject: MACAddress: AK::Array as member variable instead of C-array Problem: - C-style arrays do not automatically provide bounds checking and are less type safe overall. - `__builtin_memcmp` is not a constant expression in the current gcc. Solution: - Change private m_data to be AK::Array. - Eliminate constructor from C-style array. - Change users of the C-style array constructor to use the default constructor. - Change `operator==()` to be a hand-written comparison loop and let the optimizer figure out to use `memcmp`. --- Kernel/Net/E1000NetworkAdapter.cpp | 3 ++- Kernel/Net/RTL8139NetworkAdapter.cpp | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) (limited to 'Kernel/Net') diff --git a/Kernel/Net/E1000NetworkAdapter.cpp b/Kernel/Net/E1000NetworkAdapter.cpp index e884e297c3..8f0e8aef84 100644 --- a/Kernel/Net/E1000NetworkAdapter.cpp +++ b/Kernel/Net/E1000NetworkAdapter.cpp @@ -24,6 +24,7 @@ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +#include #include #include #include @@ -258,7 +259,7 @@ u32 E1000NetworkAdapter::read_eeprom(u8 address) void E1000NetworkAdapter::read_mac_address() { if (m_has_eeprom) { - u8 mac[6]; + MACAddress mac {}; u32 tmp = read_eeprom(0); mac[0] = tmp & 0xff; mac[1] = tmp >> 8; diff --git a/Kernel/Net/RTL8139NetworkAdapter.cpp b/Kernel/Net/RTL8139NetworkAdapter.cpp index efb26fdb92..f0faa21cd8 100644 --- a/Kernel/Net/RTL8139NetworkAdapter.cpp +++ b/Kernel/Net/RTL8139NetworkAdapter.cpp @@ -24,6 +24,7 @@ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +#include #include #include @@ -284,7 +285,7 @@ void RTL8139NetworkAdapter::reset() void RTL8139NetworkAdapter::read_mac_address() { - u8 mac[6]; + MACAddress mac {}; for (int i = 0; i < 6; i++) mac[i] = in8(REG_MAC + i); set_mac_address(mac); -- cgit v1.2.3