Skip to content

Commit 2d4c89b

Browse files
committed
make use of %zd
1 parent 2f109c4 commit 2d4c89b

15 files changed

+60
-61
lines changed

cores/esp8266/Updater.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -87,18 +87,18 @@ bool UpdaterClass::begin(size_t size, int command, int ledPin, uint8_t ledOn) {
8787
uintptr_t updateStartAddress = 0;
8888
if (command == U_FLASH) {
8989
//size of current sketch rounded to a sector
90-
uint32_t currentSketchSize = (ESP.getSketchSize() + FLASH_SECTOR_SIZE - 1) & (~(FLASH_SECTOR_SIZE - 1));
90+
size_t currentSketchSize = (ESP.getSketchSize() + FLASH_SECTOR_SIZE - 1) & (~(FLASH_SECTOR_SIZE - 1));
9191
//address of the end of the space available for sketch and update
9292
uintptr_t updateEndAddress = (uintptr_t)&_SPIFFS_start - 0x40200000;
9393
//size of the update rounded to a sector
94-
uint32_t roundedSize = (size + FLASH_SECTOR_SIZE - 1) & (~(FLASH_SECTOR_SIZE - 1));
94+
size_t roundedSize = (size + FLASH_SECTOR_SIZE - 1) & (~(FLASH_SECTOR_SIZE - 1));
9595
//address where we will start writing the update
9696
updateStartAddress = (updateEndAddress > roundedSize)? (updateEndAddress - roundedSize) : 0;
9797

9898
#ifdef DEBUG_UPDATER
99-
DEBUG_UPDATER.printf("[begin] roundedSize: 0x%08X (%d)\n", roundedSize, roundedSize);
100-
DEBUG_UPDATER.printf("[begin] updateEndAddress: 0x%08X (%d)\n", (int)updateEndAddress, (int)updateEndAddress);
101-
DEBUG_UPDATER.printf("[begin] currentSketchSize: 0x%08X (%d)\n", currentSketchSize, currentSketchSize);
99+
DEBUG_UPDATER.printf("[begin] roundedSize: 0x%08zX (%zd)\n", roundedSize, roundedSize);
100+
DEBUG_UPDATER.printf("[begin] updateEndAddress: 0x%08zX (%zd)\n", updateEndAddress, updateEndAddress);
101+
DEBUG_UPDATER.printf("[begin] currentSketchSize: 0x%08zX (%zd)\n", currentSketchSize, currentSketchSize);
102102
#endif
103103

104104
//make sure that the size of both sketches is less than the total space (updateEndAddress)
@@ -133,7 +133,7 @@ bool UpdaterClass::begin(size_t size, int command, int ledPin, uint8_t ledOn) {
133133
#ifdef DEBUG_UPDATER
134134
DEBUG_UPDATER.printf("[begin] _startAddress: 0x%08X (%d)\n", _startAddress, _startAddress);
135135
DEBUG_UPDATER.printf("[begin] _currentAddress: 0x%08X (%d)\n", _currentAddress, _currentAddress);
136-
DEBUG_UPDATER.printf("[begin] _size: 0x%08X (%d)\n", (int)_size, (int)_size);
136+
DEBUG_UPDATER.printf("[begin] _size: 0x%08zX (%zd)\n", _size, _size);
137137
#endif
138138

139139
_md5.begin();
@@ -159,7 +159,7 @@ bool UpdaterClass::end(bool evenIfRemaining){
159159

160160
if(hasError() || (!isFinished() && !evenIfRemaining)){
161161
#ifdef DEBUG_UPDATER
162-
DEBUG_UPDATER.printf("premature end: res:%u, pos:%u/%u\n", getError(), (unsigned)progress(), (unsigned)_size);
162+
DEBUG_UPDATER.printf("premature end: res:%u, pos:%zu/%zu\n", getError(), progress(), _size);
163163
#endif
164164

165165
_reset();
@@ -199,10 +199,10 @@ bool UpdaterClass::end(bool evenIfRemaining){
199199
eboot_command_write(&ebcmd);
200200

201201
#ifdef DEBUG_UPDATER
202-
DEBUG_UPDATER.printf("Staged: address:0x%08X, size:0x%08X\n", _startAddress, (unsigned)_size);
202+
DEBUG_UPDATER.printf("Staged: address:0x%08X, size:0x%08zX\n", _startAddress, _size);
203203
}
204204
else if (_command == U_SPIFFS) {
205-
DEBUG_UPDATER.printf("SPIFFS: address:0x%08X, size:0x%08X\n", _startAddress, (unsigned)_size);
205+
DEBUG_UPDATER.printf("SPIFFS: address:0x%08X, size:0x%08zX\n", _startAddress, _size);
206206
#endif
207207
}
208208

cores/esp8266/spiffs_api.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -220,9 +220,9 @@ class SPIFFSImpl : public FSImpl
220220
size_t cacheBufSize = SPIFFS_buffer_bytes_for_cache(&_fs, _maxOpenFds);
221221

222222
if (!_workBuf) {
223-
DEBUGV("SPIFFSImpl: allocating %d+%d+%d=%d bytes\r\n",
224-
(int)workBufSize, (int)fdsBufSize, (int)cacheBufSize,
225-
(int)(workBufSize + fdsBufSize + cacheBufSize));
223+
DEBUGV("SPIFFSImpl: allocating %zd+%zd+%zd=%zd bytes\r\n",
224+
workBufSize, fdsBufSize, cacheBufSize,
225+
workBufSize + fdsBufSize + cacheBufSize);
226226
_workBuf.reset(new uint8_t[workBufSize]);
227227
_fdsBuf.reset(new uint8_t[fdsBufSize]);
228228
_cacheBuf.reset(new uint8_t[cacheBufSize]);

libraries/ESP8266HTTPClient/src/ESP8266HTTPClient.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -734,7 +734,7 @@ int HTTPClient::sendRequest(const char * type, Stream * stream, size_t size)
734734
free(buff);
735735

736736
if(size && (int) size != bytesWritten) {
737-
DEBUG_HTTPCLIENT("[HTTP-Client][sendRequest] Stream payload bytesWritten %d and size %d mismatch!.\n", bytesWritten, (int)size);
737+
DEBUG_HTTPCLIENT("[HTTP-Client][sendRequest] Stream payload bytesWritten %d and size %zd mismatch!.\n", bytesWritten, size);
738738
DEBUG_HTTPCLIENT("[HTTP-Client][sendRequest] ERROR SEND PAYLOAD FAILED!");
739739
return returnError(HTTPC_ERROR_SEND_PAYLOAD_FAILED);
740740
} else {

libraries/ESP8266WebServer/src/ESP8266WebServer.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -439,7 +439,7 @@ void ESP8266WebServer::sendContent(const String& content) {
439439
size_t len = content.length();
440440
if(_chunked) {
441441
char chunkSize[11];
442-
sprintf(chunkSize, "%x\r\n", (unsigned)len);
442+
sprintf(chunkSize, "%zx\r\n", len);
443443
_currentClientWrite(chunkSize, strlen(chunkSize));
444444
}
445445
_currentClientWrite(content.c_str(), len);
@@ -459,7 +459,7 @@ void ESP8266WebServer::sendContent_P(PGM_P content, size_t size) {
459459
const char * footer = "\r\n";
460460
if(_chunked) {
461461
char chunkSize[11];
462-
sprintf(chunkSize, "%x\r\n", (unsigned)size);
462+
sprintf(chunkSize, "%zx\r\n", size);
463463
_currentClientWrite(chunkSize, strlen(chunkSize));
464464
}
465465
_currentClientWrite_P(content, size);

libraries/ESP8266WiFi/src/WiFiClientSecureBearSSL.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1405,7 +1405,7 @@ extern "C" {
14051405
int freeheap = ESP.getFreeHeap();
14061406
static int laststack, lastheap, laststack2;
14071407
if ((laststack != freestack) || (lastheap != freeheap) || (laststack2 != (int)br_esp8266_stack_proxy_usage())) {
1408-
Serial.printf("%s:%s(%d): FREESTACK=%d, STACK2USAGE=%d, FREEHEAP=%d\n", file, fcn, line, freestack, (int)br_esp8266_stack_proxy_usage(), freeheap);
1408+
Serial.printf("%s:%s(%d): FREESTACK=%d, STACK2USAGE=%zd, FREEHEAP=%d\n", file, fcn, line, freestack, br_esp8266_stack_proxy_usage(), freeheap);
14091409
if (freestack < 256) {
14101410
Serial.printf("!!! Out of main stack space\n");
14111411
}

tests/host/Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ MOCK_CPP_FILES_COMMON := $(addprefix common/,\
6060
Arduino.cpp \
6161
spiffs_mock.cpp \
6262
WMath.cpp \
63-
HardwareSerial.cpp \
63+
MockSerial.cpp \
6464
MockTools.cpp \
6565
)
6666

@@ -222,7 +222,7 @@ MOCK_ARDUINO_LIBS := \
222222
common/MockWiFiServerSocket.cpp \
223223
common/MockWiFiServer.cpp \
224224
common/UdpContextSocket.cpp \
225-
common/MockWire.cpp \
225+
common/HostWiring.cpp \
226226
common/MockEsp.cpp \
227227
common/MockEEPROM.cpp \
228228
common/MockSPI.cpp \

tests/host/common/ArduinoMain.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ int main (int argc, char* const argv [])
113113
exit(EXIT_FAILURE);
114114
}
115115
}
116-
116+
117117
// setup global global_ipv4_netfmt
118118
wifi_get_ip_info(0, nullptr);
119119

@@ -122,9 +122,9 @@ int main (int argc, char* const argv [])
122122
{
123123
if (!fast)
124124
usleep(10000); // not 100% cpu
125-
125+
126126
loop();
127-
127+
128128
// check incoming udp
129129
for (auto& udp: udps)
130130
{
@@ -133,11 +133,10 @@ int main (int argc, char* const argv [])
133133
p.events = POLLIN;
134134
if (poll(&p, 1, 0) && p.revents == POLLIN)
135135
{
136-
fprintf(stderr, MOCK "UDP poll(%d) -> cb\r", (int)p.fd);
136+
fprintf(stderr, MOCK "UDP poll(%d) -> cb\r", p.fd);
137137
udp.second->mock_cb();
138138
}
139139
}
140-
141140
}
142141
return 0;
143142
}

tests/host/common/ClientContextSocket.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ size_t mockFillInBuf (int sock, char* ccinbuf, size_t& ccinbufsize)
7373
if (ret == -1)
7474
{
7575
if (errno != EAGAIN)
76-
fprintf(stderr, MOCK "ClientContext::(read/peek): filling buffer for %d bytes: %s\n", (int)maxread, strerror(errno));
76+
fprintf(stderr, MOCK "ClientContext::(read/peek): filling buffer for %zd bytes: %s\n", maxread, strerror(errno));
7777
ret = 0;
7878
}
7979
return ccinbufsize += ret;
@@ -82,7 +82,7 @@ size_t mockFillInBuf (int sock, char* ccinbuf, size_t& ccinbufsize)
8282
size_t mockPeekBytes (int sock, char* dst, size_t usersize, int timeout_ms, char* ccinbuf, size_t& ccinbufsize)
8383
{
8484
if (usersize > CCBUFSIZE)
85-
fprintf(stderr, MOCK "CCBUFSIZE(%d) should be increased by %d bytes (-> %d)\n", CCBUFSIZE, (int)usersize - CCBUFSIZE, (int)usersize);
85+
fprintf(stderr, MOCK "CCBUFSIZE(%d) should be increased by %zd bytes (-> %zd)\n", CCBUFSIZE, usersize - CCBUFSIZE, usersize);
8686

8787
struct pollfd p;
8888
size_t retsize = 0;
@@ -143,7 +143,7 @@ size_t mockWrite (int sock, const uint8_t* data, size_t size, int timeout_ms)
143143
}
144144
if (ret != (int)size)
145145
{
146-
fprintf(stderr, MOCK "ClientContext::write: short write (%d < %d) (TODO)\n", (int)ret, (int)size);
146+
fprintf(stderr, MOCK "ClientContext::write: short write (%d < %zd) (TODO)\n", ret, size);
147147
exit(EXIT_FAILURE);
148148
}
149149
}
File renamed without changes.

tests/host/common/MockTools.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,8 @@ extern "C" void configTime(long timezone, int daylightOffset_sec,
5858
(void)server1;
5959
(void)server2;
6060
(void)server3;
61-
62-
fprintf(stderr, MOCK "configTime: TODO (tz=%dH offset=%dS) (time will be host's)\n", (int)timezone, daylightOffset_sec);
61+
62+
fprintf(stderr, MOCK "configTime: TODO (tz=%ldH offset=%dS) (time will be host's)\n", timezone, daylightOffset_sec);
6363
}
6464

6565
void stack_thunk_add_ref() { }

tests/host/common/MockWiFiServerSocket.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ void WiFiServer::begin ()
6666
{
6767
int sock;
6868
struct sockaddr_in server;
69-
69+
7070
if ((sock = socket(AF_INET, SOCK_STREAM, 0)) == -1)
7171
{
7272
perror(MOCK "socket()");
@@ -79,7 +79,7 @@ void WiFiServer::begin ()
7979
perror(MOCK "reuseport");
8080
exit(EXIT_FAILURE);
8181
}
82-
82+
8383
server.sin_family = AF_INET;
8484
server.sin_port = htons(_port);
8585
server.sin_addr.s_addr = htonl(INADDR_ANY);
@@ -88,7 +88,7 @@ void WiFiServer::begin ()
8888
perror(MOCK "bind()");
8989
exit(EXIT_FAILURE);
9090
}
91-
91+
9292
if (listen(sock, 1) == -1)
9393
{
9494
perror(MOCK "listen()");
@@ -115,7 +115,7 @@ size_t WiFiServer::write (uint8_t c)
115115

116116
size_t WiFiServer::write (const uint8_t *buf, size_t size)
117117
{
118-
fprintf(stderr, MOCK "todo: WiFiServer::write(%p, %d)\n", buf, (int)size);
118+
fprintf(stderr, MOCK "todo: WiFiServer::write(%p, %zd)\n", buf, size);
119119
return 0;
120120
}
121121

tests/host/common/UdpContextSocket.cpp

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -59,28 +59,28 @@ bool mockUDPListen (int sock, uint32_t dstaddr, uint16_t port, uint32_t mcast)
5959
fprintf(stderr, MOCK "SO_REUSEADDR failed\n");
6060

6161
struct sockaddr_in servaddr;
62-
memset(&servaddr, 0, sizeof(servaddr));
63-
64-
// Filling server information
62+
memset(&servaddr, 0, sizeof(servaddr));
63+
64+
// Filling server information
6565
servaddr.sin_family = AF_INET;
6666
//servaddr.sin_addr.s_addr = global_ipv4_netfmt?: dstaddr;
6767
servaddr.sin_addr.s_addr = htonl(INADDR_ANY);
6868
servaddr.sin_port = htons(port);
69-
70-
// Bind the socket with the server address
69+
70+
// Bind the socket with the server address
7171
if (bind(sock, (const struct sockaddr *)&servaddr, sizeof(servaddr)) < 0)
7272
{
73-
fprintf(stderr, MOCK "UDP bind on port %d failed: %s\n", port, strerror(errno));
73+
fprintf(stderr, MOCK "UDP bind on port %d failed: %s\n", port, strerror(errno));
7474
return false;
7575
}
7676
else
77-
fprintf(stderr, MOCK "UDP server on port %d (sock=%d)\n", (int)port, (int)sock);
78-
77+
fprintf(stderr, MOCK "UDP server on port %d (sock=%d)\n", (int)port, sock);
78+
7979
if (mcast)
8080
{
8181
// https://web.cs.wpi.edu/~claypool/courses/4514-B99/samples/multicast.c
8282
// https://stackoverflow.com/questions/12681097/c-choose-interface-for-udp-multicast-socket
83-
83+
8484
struct ip_mreq mreq;
8585
mreq.imr_multiaddr.s_addr = mcast;
8686
//mreq.imr_interface.s_addr = global_ipv4_netfmt?: htonl(INADDR_ANY);
@@ -99,7 +99,7 @@ bool mockUDPListen (int sock, uint32_t dstaddr, uint16_t port, uint32_t mcast)
9999
return false;
100100
}
101101
}
102-
102+
103103
return true;
104104
}
105105

@@ -114,10 +114,10 @@ size_t mockUDPFillInBuf (int sock, char* ccinbuf, size_t& ccinbufsize, uint8_t&
114114
if (ret == -1)
115115
{
116116
if (errno != EAGAIN)
117-
fprintf(stderr, MOCK "UDPContext::(read/peek): filling buffer for %d bytes: %s\n", (int)maxread, strerror(errno));
117+
fprintf(stderr, MOCK "UDPContext::(read/peek): filling buffer for %zd bytes: %s\n", maxread, strerror(errno));
118118
ret = 0;
119119
}
120-
120+
121121
if (ret > 0)
122122
{
123123
port = ntohs(((sockaddr_in*)&addrbuf)->sin_port);
@@ -136,7 +136,7 @@ size_t mockUDPFillInBuf (int sock, char* ccinbuf, size_t& ccinbufsize, uint8_t&
136136
size_t mockUDPPeekBytes (int sock, char* dst, size_t usersize, int timeout_ms, char* ccinbuf, size_t& ccinbufsize)
137137
{
138138
if (usersize > CCBUFSIZE)
139-
fprintf(stderr, MOCK "CCBUFSIZE(%d) should be increased by %d bytes (-> %d)\n", CCBUFSIZE, (int)usersize - CCBUFSIZE, (int)usersize);
139+
fprintf(stderr, MOCK "CCBUFSIZE(%d) should be increased by %zd bytes (-> %zd)\n", CCBUFSIZE, usersize - CCBUFSIZE, usersize);
140140

141141
size_t retsize = 0;
142142
if (ccinbufsize)
@@ -161,7 +161,7 @@ size_t mockUDPRead (int sock, char* dst, size_t size, int timeout_ms, char* ccin
161161

162162
size_t mockUDPWrite (int sock, const uint8_t* data, size_t size, int timeout_ms, uint32_t ipv4, uint16_t port)
163163
{
164-
// Filling server information
164+
// Filling server information
165165
struct sockaddr_in peer;
166166
peer.sin_family = AF_INET;
167167
peer.sin_addr.s_addr = ipv4; //XXFIXME should use lwip_htonl?
@@ -174,7 +174,7 @@ size_t mockUDPWrite (int sock, const uint8_t* data, size_t size, int timeout_ms,
174174
}
175175
if (ret != (int)size)
176176
{
177-
fprintf(stderr, MOCK "UDPContext::write: short write (%d < %d) (TODO)\n", (int)ret, (int)size);
177+
fprintf(stderr, MOCK "UDPContext::write: short write (%d < %zd) (TODO)\n", ret, size);
178178
exit(EXIT_FAILURE);
179179
}
180180

tests/host/common/include/UdpContext.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ class UdpContext
111111
fprintf(stderr, MOCK "TODO: implement UDP offset\n");
112112
if (!isValidOffset(pos))
113113
{
114-
fprintf(stderr, MOCK "UDPContext::seek too far (%d >= %d)\n", (int)pos, (int)_inbufsize);
114+
fprintf(stderr, MOCK "UDPContext::seek too far (%zd >= %zd)\n", pos, _inbufsize);
115115
exit(EXIT_FAILURE);
116116
}
117117
}
@@ -183,7 +183,7 @@ class UdpContext
183183
{
184184
if (size + _outbufsize > sizeof _outbuf)
185185
{
186-
fprintf(stderr, MOCK "UdpContext::append: increase CCBUFSIZE (%d -> %d)\n", CCBUFSIZE, (int)(size + _outbufsize));
186+
fprintf(stderr, MOCK "UdpContext::append: increase CCBUFSIZE (%d -> %zd)\n", CCBUFSIZE, (size + _outbufsize));
187187
exit(EXIT_FAILURE);
188188
}
189189

@@ -200,7 +200,7 @@ class UdpContext
200200
_outbufsize = 0;
201201
return ret > 0;
202202
}
203-
203+
204204
void mock_cb (void)
205205
{
206206
if (_on_rx) _on_rx();
@@ -232,14 +232,14 @@ class UdpContext
232232

233233
ip_addr_t _dst;
234234
uint16_t _dstport;
235-
235+
236236
char _inbuf [CCBUFSIZE];
237237
size_t _inbufsize = 0;
238238
char _outbuf [CCBUFSIZE];
239239
size_t _outbufsize = 0;
240240

241241
int _timeout_ms = 0;
242-
242+
243243
uint8_t addrsize;
244244
uint8_t addr[16];
245245
};

0 commit comments

Comments
 (0)