Skip to content

Commit f18bb28

Browse files
committed
fix bug #343
add __attribute__ to printf functions for better compiler warning handling. remove ICACHE_FLASH_ATTR, all cpp files are automatic in FLASH (ld script)
1 parent 1d0a923 commit f18bb28

File tree

5 files changed

+43
-41
lines changed

5 files changed

+43
-41
lines changed

cores/esp8266/Arduino.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ extern "C" {
3535

3636
#include "stdlib_noniso.h"
3737
#include "binary.h"
38-
#include "pgmspace.h"
3938
#include "esp8266_peri.h"
4039
#include "twi.h"
4140

@@ -205,6 +204,8 @@ void loop(void);
205204

206205
#ifdef __cplusplus
207206

207+
#include "pgmspace.h"
208+
208209
#include "WCharacter.h"
209210
#include "WString.h"
210211

cores/esp8266/pgmspace.cpp

+29-29
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,32 @@
11
/*
2-
pgmspace.cpp - string functions that support PROGMEM
3-
Copyright (c) 2015 Michael C. Miller. All right reserved.
2+
pgmspace.cpp - string functions that support PROGMEM
3+
Copyright (c) 2015 Michael C. Miller. All right reserved.
44
5-
This library is free software; you can redistribute it and/or
6-
modify it under the terms of the GNU Lesser General Public
7-
License as published by the Free Software Foundation; either
8-
version 2.1 of the License, or (at your option) any later version.
5+
This library is free software; you can redistribute it and/or
6+
modify it under the terms of the GNU Lesser General Public
7+
License as published by the Free Software Foundation; either
8+
version 2.1 of the License, or (at your option) any later version.
99
10-
This library is distributed in the hope that it will be useful,
11-
but WITHOUT ANY WARRANTY; without even the implied warranty of
12-
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13-
Lesser General Public License for more details.
10+
This library is distributed in the hope that it will be useful,
11+
but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13+
Lesser General Public License for more details.
1414
15-
You should have received a copy of the GNU Lesser General Public
16-
License along with this library; if not, write to the Free Software
17-
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18-
*/
15+
You should have received a copy of the GNU Lesser General Public
16+
License along with this library; if not, write to the Free Software
17+
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18+
*/
1919

2020
#include <ctype.h>
2121
#include "pgmspace.h"
2222

23-
size_t ICACHE_FLASH_ATTR strnlen_P(const char* s, size_t size) {
23+
size_t strnlen_P(const char* s, size_t size) {
2424
const char* cp;
2525
for (cp = s; size != 0 && pgm_read_byte(cp) != '\0'; cp++, size--);
26-
return (size_t)(cp - s);
26+
return (size_t) (cp - s);
2727
}
2828

29-
void* ICACHE_FLASH_ATTR memcpy_P(void* dest, const void* src, size_t count) {
29+
void* memcpy_P(void* dest, const void* src, size_t count) {
3030
const uint8_t* read = reinterpret_cast<const uint8_t*>(src);
3131
uint8_t* write = reinterpret_cast<uint8_t*>(dest);
3232

@@ -39,7 +39,7 @@ void* ICACHE_FLASH_ATTR memcpy_P(void* dest, const void* src, size_t count) {
3939
return dest;
4040
}
4141

42-
char* ICACHE_FLASH_ATTR strncpy_P(char* dest, const char* src, size_t size) {
42+
char* strncpy_P(char* dest, const char* src, size_t size) {
4343
const char* read = src;
4444
char* write = dest;
4545
char ch = '.';
@@ -48,19 +48,19 @@ char* ICACHE_FLASH_ATTR strncpy_P(char* dest, const char* src, size_t size) {
4848
ch = pgm_read_byte(read++);
4949
*write++ = ch;
5050
size--;
51-
}
51+
}
5252

5353
return dest;
5454
}
5555

56-
char* ICACHE_FLASH_ATTR strncat_P(char* dest, const char* src, size_t size) {
56+
char* strncat_P(char* dest, const char* src, size_t size) {
5757
char* write = dest;
5858

5959
while (*write != '\0')
6060
{
6161
write++;
6262
}
63-
63+
6464
const char* read = src;
6565
char ch = '.';
6666

@@ -80,7 +80,7 @@ char* ICACHE_FLASH_ATTR strncat_P(char* dest, const char* src, size_t size) {
8080
return dest;
8181
}
8282

83-
int ICACHE_FLASH_ATTR strncmp_P(const char* str1, const char* str2P, size_t size) {
83+
int strncmp_P(const char* str1, const char* str2P, size_t size) {
8484
int result = 0;
8585

8686
while (size > 0)
@@ -99,7 +99,7 @@ int ICACHE_FLASH_ATTR strncmp_P(const char* str1, const char* str2P, size_t size
9999
return result;
100100
}
101101

102-
int ICACHE_FLASH_ATTR strncasecmp_P(const char* str1, const char* str2P, size_t size) {
102+
int strncasecmp_P(const char* str1, const char* str2P, size_t size) {
103103
int result = 0;
104104

105105
while (size > 0)
@@ -118,7 +118,7 @@ int ICACHE_FLASH_ATTR strncasecmp_P(const char* str1, const char* str2P, size_t
118118
return result;
119119
}
120120

121-
int ICACHE_FLASH_ATTR printf_P(const char* formatP, ...) {
121+
int printf_P(const char* formatP, ...) {
122122
int ret;
123123
va_list arglist;
124124
va_start(arglist, formatP);
@@ -129,13 +129,13 @@ int ICACHE_FLASH_ATTR printf_P(const char* formatP, ...) {
129129

130130
ret = os_printf(format, arglist);
131131

132-
delete [] format;
132+
delete[] format;
133133

134134
va_end(arglist);
135135
return ret;
136136
}
137137

138-
int ICACHE_FLASH_ATTR snprintf_P(char* str, size_t strSize, const char* formatP, ...) {
138+
int snprintf_P(char* str, size_t strSize, const char* formatP, ...) {
139139
int ret;
140140
va_list arglist;
141141
va_start(arglist, formatP);
@@ -146,7 +146,7 @@ int ICACHE_FLASH_ATTR snprintf_P(char* str, size_t strSize, const char* formatP,
146146
return ret;
147147
}
148148

149-
int ICACHE_FLASH_ATTR vsnprintf_P(char* str, size_t strSize, const char* formatP, va_list ap) {
149+
int vsnprintf_P(char* str, size_t strSize, const char* formatP, va_list ap) {
150150
int ret;
151151

152152
size_t fmtLen = strlen_P(formatP);
@@ -155,7 +155,7 @@ int ICACHE_FLASH_ATTR vsnprintf_P(char* str, size_t strSize, const char* formatP
155155

156156
ret = ets_vsnprintf(str, strSize, format, ap);
157157

158-
delete [] format;
158+
delete[] format;
159159

160160
return ret;
161-
}
161+
}

cores/esp8266/pgmspace.h

+9-9
Original file line numberDiff line numberDiff line change
@@ -32,26 +32,26 @@ typedef uint32_t prog_uint32_t;
3232

3333
#define SIZE_IRRELEVANT 0x7fffffff
3434

35-
extern void* memcpy_P(void* dest, const void* src, size_t count);
35+
void* memcpy_P(void* dest, const void* src, size_t count);
3636

37-
extern char* strncpy_P(char* dest, const char* src, size_t size);
37+
char* strncpy_P(char* dest, const char* src, size_t size);
3838
#define strcpy_P(dest, src) strncpy_P((dest), (src), SIZE_IRRELEVANT)
3939

40-
extern char* strncat_P(char* dest, const char* src, size_t size);
40+
char* strncat_P(char* dest, const char* src, size_t size);
4141
#define strcat_P(dest, src) strncat_P((dest), (src), SIZE_IRRELEVANT)
4242

43-
extern int strncmp_P(const char* str1, const char* str2P, size_t size);
43+
int strncmp_P(const char* str1, const char* str2P, size_t size);
4444
#define strcmp_P(str1, str2P) strncmp_P((str1), (str2P), SIZE_IRRELEVANT)
4545

46-
extern int strncasecmp_P(const char* str1, const char* str2P, size_t size);
46+
int strncasecmp_P(const char* str1, const char* str2P, size_t size);
4747
#define strcasecmp_P(str1, str2P) strncasecmp_P((str1), (str2P), SIZE_IRRELEVANT)
4848

49-
extern size_t strnlen_P(const char *s, size_t size);
49+
size_t strnlen_P(const char *s, size_t size);
5050
#define strlen_P(strP) strnlen_P((strP), SIZE_IRRELEVANT)
5151

52-
extern int printf_P(const char *formatP, ...);
53-
extern int snprintf_P(char *str, size_t strSize, const char *formatP, ...);
54-
extern int vsnprintf_P(char *str, size_t strSize, const char *formatP, va_list ap);
52+
int printf_P(const char *formatP, ...) __attribute__ ((format (printf, 1, 2)));
53+
int snprintf_P(char *str, size_t strSize, const char *formatP, ...) __attribute__ ((format (printf, 3, 4)));
54+
int vsnprintf_P(char *str, size_t strSize, const char *formatP, va_list ap) __attribute__ ((format (printf, 3, 0)));
5555

5656
// flash memory must be read using 32 bit aligned addresses else a processor
5757
// exception will be triggered

libraries/ESP8266WiFi/src/ESP8266WiFi.h

+1
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ class ESP8266WiFiClass
116116
*/
117117
uint8_t* softAPmacAddress(uint8_t* mac);
118118
String softAPmacAddress(void);
119+
119120
/*
120121
* Get the station interface IP address.
121122
*

tools/sdk/include/ets_sys.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ void ets_isr_unmask(int intr);
118118
void ets_isr_attach(int intr, int_handler_t handler, void *arg);
119119
void ets_intr_lock();
120120
void ets_intr_unlock();
121-
int ets_vsnprintf(char * s, size_t n, const char * format, va_list arg);
122-
int ets_vprintf(const char * format, va_list arg);
121+
int ets_vsnprintf(char * s, size_t n, const char * format, va_list arg) __attribute__ ((format (printf, 3, 0)));
122+
int ets_vprintf(const char * format, va_list arg) __attribute__ ((format (printf, 1, 0)));
123123

124124
#endif /* _ETS_SYS_H */

0 commit comments

Comments
 (0)