Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
M
mongoose
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
mongoose
Commits
3a9a9c7a
Commit
3a9a9c7a
authored
Sep 23, 2015
by
Marko Mikulicic
Committed by
Sergey Lyubka
Sep 25, 2015
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Enable printf format warnings for mg_printf
PUBLISHED_FROM=61a52651a2542cb89b155623781a5fcbf64779f3
parent
13238b1a
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
22 additions
and
9 deletions
+22
-9
mongoose.c
mongoose.c
+12
-9
mongoose.h
mongoose.h
+10
-0
No files found.
mongoose.c
View file @
3a9a9c7a
...
...
@@ -4448,20 +4448,23 @@ static void mg_send_http_file2(struct mg_connection *nc, const char *path,
gmt_time_string
(
last_modified
,
sizeof
(
last_modified
),
&
st
->
st_mtime
);
mime_type
=
get_mime_type
(
path
,
"text/plain"
,
opts
);
/*
* breaking up printing in three separate mg_printf invocations
* otherwise crashes inside newlib on ESP8266.
* Not a big performance penalty on desktop.
* Content length casted to size_t because:
* 1) that's the maximum buffer size anyway
* 2) ESP8266 RTOS SDK newlib vprintf cannot contain a 64bit arg at non-last
* position
* TODO(mkm): fix ESP8266 RTOS SDK
*/
mg_printf
(
nc
,
"HTTP/1.1 %d %s
\r\n
"
"Date: %s
\r\n
"
"Last-Modified: %s
\r\n
"
"Accept-Ranges: bytes
\r\n
"
"Content-Type: %.*s
\r\n
"
,
"Content-Type: %.*s
\r\n
"
"Content-Length: %"
SIZE_T_FMT
"
\r\n
"
"%sEtag: %s
\r\n\r\n
"
,
status_code
,
status_message
,
current_time
,
last_modified
,
(
int
)
mime_type
.
len
,
mime_type
.
p
);
mg_printf
(
nc
,
"Content-Length: %"
INT64_FMT
"
\r\n
"
,
cl
);
mg_printf
(
nc
,
"%sEtag: %s
\r\n\r\n
"
,
range
,
etag
);
(
int
)
mime_type
.
len
,
mime_type
.
p
,
(
size_t
)
cl
,
range
,
etag
);
nc
->
proto_data
=
(
void
*
)
dp
;
dp
->
cl
=
cl
;
...
...
@@ -5816,8 +5819,8 @@ struct mg_connection *mg_connect_http(struct mg_mgr *mgr,
/* Do not add port. See https://github.com/cesanta/mongoose/pull/304 */
addr
[
addr_len
]
=
'\0'
;
}
mg_printf
(
nc
,
"%s /%s HTTP/1.1
\r\n
Host: %s
\r\n
Content-Length: %lu
\r\n
%s
\r\n
%s"
,
mg_printf
(
nc
,
"%s /%s HTTP/1.1
\r\n
Host: %s
\r\n
Content-Length: %"
SIZE_T_FMT
"
\r\n
%s
\r\n
%s"
,
post_data
==
NULL
?
"GET"
:
"POST"
,
path
,
addr
,
post_data
==
NULL
?
0
:
strlen
(
post_data
),
extra_headers
==
NULL
?
""
:
extra_headers
,
...
...
mongoose.h
View file @
3a9a9c7a
...
...
@@ -233,7 +233,11 @@ struct dirent *readdir(DIR *dir);
#define INVALID_SOCKET (-1)
#define INT64_FMT PRId64
#if defined(ESP8266) || defined(MG_ESP8266)
#define SIZE_T_FMT "u"
#else
#define SIZE_T_FMT "zu"
#endif
#define to64(x) strtoll(x, NULL, 10)
typedef
int
sock_t
;
typedef
struct
stat
cs_stat_t
;
...
...
@@ -905,6 +909,12 @@ const char *mg_set_ssl(struct mg_connection *nc, const char *cert,
*/
int
mg_send
(
struct
mg_connection
*
,
const
void
*
buf
,
int
len
);
/* Enables format string warnings for mg_printf */
#if defined(__GNUC__)
__attribute__
((
format
(
printf
,
2
,
3
)))
#endif
/* don't separate from mg_printf declaration */
/*
* Send `printf`-style formatted data to the connection.
*
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment