1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 13:48:12 +00:00

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`.
This commit is contained in:
Lenny Maiorani 2020-11-16 17:41:46 -07:00 committed by Andreas Kling
parent 700fe315cf
commit bdf3baa8ac
4 changed files with 39 additions and 23 deletions

View file

@ -24,6 +24,7 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <AK/MACAddress.h>
#include <Kernel/IO.h>
#include <Kernel/Net/E1000NetworkAdapter.h>
#include <Kernel/Thread.h>
@ -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;