Skip to content

Commit 73eca0f

Browse files
committed
Merge branch 'ide-1.5.x-warnings' of github.com:matthijskooijman/Arduino into ide-1.5.x
2 parents 8e9b8dc + cc9ef2f commit 73eca0f

File tree

9 files changed

+51
-31
lines changed

9 files changed

+51
-31
lines changed

cores/arduino/IPAddress.cpp

+12-12
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

cores/arduino/IPAddress.h

+11-6
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);

cores/arduino/Stream.cpp

+1-1
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();

cores/arduino/USB/CDC.cpp

+5
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)

cores/arduino/USB/USBCore.cpp

+1-1
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);

cores/arduino/avr/dtostrf.c

+2
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);

cores/arduino/syscalls_sam3.c

+16-8
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,14 @@
3838
#include <sys/stat.h>
3939
#endif
4040

41+
// Helper macro to mark unused parameters and prevent compiler warnings.
42+
// Appends _UNUSED to the variable name to prevent accidentally using them.
43+
#ifdef __GNUC__
44+
# define UNUSED(x) x ## _UNUSED __attribute__((__unused__))
45+
#else
46+
# define UNUSED(x) x ## _UNUSED
47+
#endif
48+
4149
/*----------------------------------------------------------------------------
4250
* Exported variables
4351
*----------------------------------------------------------------------------*/
@@ -69,39 +77,39 @@ extern caddr_t _sbrk ( int incr )
6977
return (caddr_t) prev_heap ;
7078
}
7179

72-
extern int link( char *cOld, char *cNew )
80+
extern int link( UNUSED(char *cOld), UNUSED(char *cNew) )
7381
{
7482
return -1 ;
7583
}
7684

77-
extern int _close( int file )
85+
extern int _close( UNUSED(int file) )
7886
{
7987
return -1 ;
8088
}
8189

82-
extern int _fstat( int file, struct stat *st )
90+
extern int _fstat( UNUSED(int file), struct stat *st )
8391
{
8492
st->st_mode = S_IFCHR ;
8593

8694
return 0 ;
8795
}
8896

89-
extern int _isatty( int file )
97+
extern int _isatty( UNUSED(int file) )
9098
{
9199
return 1 ;
92100
}
93101

94-
extern int _lseek( int file, int ptr, int dir )
102+
extern int _lseek( UNUSED(int file), UNUSED(int ptr), UNUSED(int dir) )
95103
{
96104
return 0 ;
97105
}
98106

99-
extern int _read(int file, char *ptr, int len)
107+
extern int _read(UNUSED(int file), UNUSED(char *ptr), UNUSED(int len) )
100108
{
101109
return 0 ;
102110
}
103111

104-
extern int _write( int file, char *ptr, int len )
112+
extern int _write( UNUSED(int file), char *ptr, int len )
105113
{
106114
int iIndex ;
107115

@@ -129,7 +137,7 @@ extern void _exit( int status )
129137
for ( ; ; ) ;
130138
}
131139

132-
extern void _kill( int pid, int sig )
140+
extern void _kill( UNUSED(int pid), UNUSED(int sig) )
133141
{
134142
return ;
135143
}

cores/arduino/wiring_analog.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ uint32_t analogRead(uint32_t ulPin)
150150
// Enable the corresponding channel
151151
if (ulChannel != latestSelectedChannel) {
152152
adc_enable_channel( ADC, ulChannel );
153-
if ( latestSelectedChannel != -1 )
153+
if ( latestSelectedChannel != (uint32_t)-1 )
154154
adc_disable_channel( ADC, latestSelectedChannel );
155155
latestSelectedChannel = ulChannel;
156156
}
@@ -293,7 +293,7 @@ void analogWrite(uint32_t ulPin, uint32_t ulValue) {
293293
ETCChannel channel = g_APinDescription[ulPin].ulTCChannel;
294294
static const uint32_t channelToChNo[] = { 0, 0, 1, 1, 2, 2, 0, 0, 1, 1, 2, 2, 0, 0, 1, 1, 2, 2 };
295295
static const uint32_t channelToAB[] = { 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0 };
296-
static const Tc *channelToTC[] = {
296+
static Tc *channelToTC[] = {
297297
TC0, TC0, TC0, TC0, TC0, TC0,
298298
TC1, TC1, TC1, TC1, TC1, TC1,
299299
TC2, TC2, TC2, TC2, TC2, TC2 };

variants/arduino_due_x/variant.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -380,7 +380,7 @@ void init( void )
380380
__libc_init_array();
381381

382382
// Disable pull-up on every pin
383-
for (int i = 0; i < PINS_COUNT; i++)
383+
for (unsigned i = 0; i < PINS_COUNT; i++)
384384
digitalWrite(i, LOW);
385385

386386
// Enable parallel access on PIO output data registers

0 commit comments

Comments
 (0)