Skip to content

Commit b673b72

Browse files
committed
Merge branch 'ide-1.5.x-warnings' of github.com:matthijskooijman/Arduino into ide-1.5.x
2 parents d9d8f50 + 5c6ee61 commit b673b72

File tree

16 files changed

+100
-68
lines changed

16 files changed

+100
-68
lines changed

hardware/arduino/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

hardware/arduino/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

hardware/arduino/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);

hardware/arduino/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();

hardware/arduino/sam/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

hardware/arduino/sam/cores/arduino/IPAddress.h

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,23 @@
2020
#ifndef IPAddress_h
2121
#define IPAddress_h
2222

23+
#include <stdint.h>
2324
#include <Printable.h>
2425

2526
// A class to make it easier to handle and pass around IP addresses
2627

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

3641
public:
3742
// Constructors
@@ -42,13 +47,13 @@ class IPAddress : public Printable {
4247

4348
// Overloaded cast operator to allow IPAddress objects to be used where a pointer
4449
// to a four-byte uint8_t array is expected
45-
operator uint32_t() const { return *((uint32_t*)_address); };
46-
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; };
4752
bool operator==(const uint8_t* addr) const;
4853

4954
// Overloaded index operator to allow getting and setting individual octets of the address
50-
uint8_t operator[](int index) const { return _address[index]; };
51-
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]; };
5257

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

hardware/arduino/sam/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();

hardware/arduino/sam/cores/arduino/USB/CDC.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,10 +147,15 @@ bool WEAK CDC_Setup(Setup& setup)
147147
int _serialPeek = -1;
148148
void Serial_::begin(uint32_t baud_count)
149149
{
150+
// suppress "unused parameter" warning
151+
(void)baud_count;
150152
}
151153

152154
void Serial_::begin(uint32_t baud_count, uint8_t config)
153155
{
156+
// suppress "unused parameter" warning
157+
(void)baud_count;
158+
(void)config;
154159
}
155160

156161
void Serial_::end(void)

hardware/arduino/sam/cores/arduino/USB/USBCore.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ uint32_t USBD_Available(uint32_t ep)
139139
// Return number of bytes read
140140
uint32_t USBD_Recv(uint32_t ep, void* d, uint32_t len)
141141
{
142-
if (!_usbConfiguration || len < 0)
142+
if (!_usbConfiguration)
143143
return -1;
144144

145145
LockEP lock(ep);

hardware/arduino/sam/cores/arduino/avr/dtostrf.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
1919
*/
2020

21+
#include <stdio.h>
22+
2123
char *dtostrf (double val, signed char width, unsigned char prec, char *sout) {
2224
char fmt[20];
2325
sprintf(fmt, "%%%d.%df", width, prec);

0 commit comments

Comments
 (0)