Skip to content

Commit 60d3f14

Browse files
committed
Merge branch 'ide-1.5.x-warnings' of github.com:matthijskooijman/Arduino into ide-1.5.x
2 parents dfad568 + fb1afef commit 60d3f14

File tree

4 files changed

+24
-22
lines changed

4 files changed

+24
-22
lines changed

avr/cores/arduino/Arduino.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#define Arduino_h
2222

2323
#include <stdlib.h>
24+
#include <stdbool.h>
2425
#include <string.h>
2526
#include <math.h>
2627

@@ -43,9 +44,6 @@ void yield(void);
4344
#define OUTPUT 0x1
4445
#define INPUT_PULLUP 0x2
4546

46-
#define true 0x1
47-
#define false 0x0
48-
4947
#define PI 3.1415926535897932384626433832795
5048
#define HALF_PI 1.5707963267948966192313216916398
5149
#define TWO_PI 6.283185307179586476925286766559

avr/cores/arduino/IPAddress.cpp

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,53 +22,53 @@
2222

2323
IPAddress::IPAddress()
2424
{
25-
memset(_address, 0, sizeof(_address));
25+
_address.dword = 0;
2626
}
2727

2828
IPAddress::IPAddress(uint8_t first_octet, uint8_t second_octet, uint8_t third_octet, uint8_t fourth_octet)
2929
{
30-
_address[0] = first_octet;
31-
_address[1] = second_octet;
32-
_address[2] = third_octet;
33-
_address[3] = fourth_octet;
30+
_address.bytes[0] = first_octet;
31+
_address.bytes[1] = second_octet;
32+
_address.bytes[2] = third_octet;
33+
_address.bytes[3] = fourth_octet;
3434
}
3535

3636
IPAddress::IPAddress(uint32_t address)
3737
{
38-
memcpy(_address, &address, sizeof(_address));
38+
_address.dword = address;
3939
}
4040

4141
IPAddress::IPAddress(const uint8_t *address)
4242
{
43-
memcpy(_address, address, sizeof(_address));
43+
memcpy(_address.bytes, address, sizeof(_address.bytes));
4444
}
4545

4646
IPAddress& IPAddress::operator=(const uint8_t *address)
4747
{
48-
memcpy(_address, address, sizeof(_address));
48+
memcpy(_address.bytes, address, sizeof(_address.bytes));
4949
return *this;
5050
}
5151

5252
IPAddress& IPAddress::operator=(uint32_t address)
5353
{
54-
memcpy(_address, (const uint8_t *)&address, sizeof(_address));
54+
_address.dword = address;
5555
return *this;
5656
}
5757

5858
bool IPAddress::operator==(const uint8_t* addr) const
5959
{
60-
return memcmp(addr, _address, sizeof(_address)) == 0;
60+
return memcmp(addr, _address.bytes, sizeof(_address.bytes)) == 0;
6161
}
6262

6363
size_t IPAddress::printTo(Print& p) const
6464
{
6565
size_t n = 0;
6666
for (int i =0; i < 3; i++)
6767
{
68-
n += p.print(_address[i], DEC);
68+
n += p.print(_address.bytes[i], DEC);
6969
n += p.print('.');
7070
}
71-
n += p.print(_address[3], DEC);
71+
n += p.print(_address.bytes[3], DEC);
7272
return n;
7373
}
7474

avr/cores/arduino/IPAddress.h

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,16 @@
2727

2828
class IPAddress : public Printable {
2929
private:
30-
uint8_t _address[4]; // IPv4 address
30+
union {
31+
uint8_t bytes[4]; // IPv4 address
32+
uint32_t dword;
33+
} _address;
34+
3135
// Access the raw byte array containing the address. Because this returns a pointer
3236
// to the internal structure rather than a copy of the address this function should only
3337
// be used when you know that the usage of the returned uint8_t* will be transient and not
3438
// stored.
35-
uint8_t* raw_address() { return _address; };
39+
uint8_t* raw_address() { return _address.bytes; };
3640

3741
public:
3842
// Constructors
@@ -43,13 +47,13 @@ class IPAddress : public Printable {
4347

4448
// Overloaded cast operator to allow IPAddress objects to be used where a pointer
4549
// to a four-byte uint8_t array is expected
46-
operator uint32_t() const { return *((uint32_t*)_address); };
47-
bool operator==(const IPAddress& addr) const { return (*((uint32_t*)_address)) == (*((uint32_t*)addr._address)); };
50+
operator uint32_t() const { return _address.dword; };
51+
bool operator==(const IPAddress& addr) const { return _address.dword == addr._address.dword; };
4852
bool operator==(const uint8_t* addr) const;
4953

5054
// Overloaded index operator to allow getting and setting individual octets of the address
51-
uint8_t operator[](int index) const { return _address[index]; };
52-
uint8_t& operator[](int index) { return _address[index]; };
55+
uint8_t operator[](int index) const { return _address.bytes[index]; };
56+
uint8_t& operator[](int index) { return _address.bytes[index]; };
5357

5458
// Overloaded copy operators to allow initialisation of IPAddress objects from other types
5559
IPAddress& operator=(const uint8_t *address);

avr/cores/arduino/Stream.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ float Stream::parseFloat(char skipChar){
176176
boolean isNegative = false;
177177
boolean isFraction = false;
178178
long value = 0;
179-
char c;
179+
int c;
180180
float fraction = 1.0;
181181

182182
c = peekNextDigit();

0 commit comments

Comments
 (0)