Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
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
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
esp
mongoose
Commits
2de96bd5
Commit
2de96bd5
authored
Aug 02, 2013
by
Sergey Lyubka
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Workaround for non-compliant vsnprintf()
parent
f815c315
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
24 additions
and
1 deletion
+24
-1
mongoose.c
mongoose.c
+24
-1
No files found.
mongoose.c
View file @
2de96bd5
...
@@ -1629,6 +1629,24 @@ int mg_write(struct mg_connection *conn, const void *buf, size_t len) {
...
@@ -1629,6 +1629,24 @@ int mg_write(struct mg_connection *conn, const void *buf, size_t len) {
return
(
int
)
total
;
return
(
int
)
total
;
}
}
// Alternative alloc_vprintf() for non-compliant C runtimes
static
int
alloc_vprintf2
(
char
**
buf
,
const
char
*
fmt
,
va_list
ap
)
{
va_list
ap_copy
;
int
size
=
MG_BUF_LEN
;
int
len
=
-
1
;
*
buf
=
NULL
;
while
(
len
==
-
1
)
{
if
(
*
buf
)
free
(
*
buf
);
*
buf
=
malloc
(
size
*=
4
);
if
(
!*
buf
)
break
;
va_copy
(
ap_copy
,
ap
);
len
=
vsnprintf
(
*
buf
,
size
,
fmt
,
ap_copy
);
}
return
len
;
}
// Print message to buffer. If buffer is large enough to hold the message,
// Print message to buffer. If buffer is large enough to hold the message,
// return buffer. If buffer is to small, allocate large enough buffer on heap,
// return buffer. If buffer is to small, allocate large enough buffer on heap,
// and return allocated buffer.
// and return allocated buffer.
...
@@ -1644,7 +1662,12 @@ static int alloc_vprintf(char **buf, size_t size, const char *fmt, va_list ap) {
...
@@ -1644,7 +1662,12 @@ static int alloc_vprintf(char **buf, size_t size, const char *fmt, va_list ap) {
va_copy
(
ap_copy
,
ap
);
va_copy
(
ap_copy
,
ap
);
len
=
vsnprintf
(
NULL
,
0
,
fmt
,
ap_copy
);
len
=
vsnprintf
(
NULL
,
0
,
fmt
,
ap_copy
);
if
(
len
>
(
int
)
size
&&
if
(
len
<
0
)
{
// C runtime is not standard compliant, vsnprintf() returned -1.
// Switch to alternative code path that uses incremental allocations.
va_copy
(
ap_copy
,
ap
);
len
=
alloc_vprintf2
(
buf
,
fmt
,
ap
);
}
else
if
(
len
>
(
int
)
size
&&
(
size
=
len
+
1
)
>
0
&&
(
size
=
len
+
1
)
>
0
&&
(
*
buf
=
(
char
*
)
malloc
(
size
))
==
NULL
)
{
(
*
buf
=
(
char
*
)
malloc
(
size
))
==
NULL
)
{
len
=
-
1
;
// Allocation failed, mark failure
len
=
-
1
;
// Allocation failed, mark failure
...
...
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