1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 18:27:35 +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/RTL8139NetworkAdapter.h>
@ -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);