Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
Synchronet
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Main
Synchronet
Commits
7e614242
Commit
7e614242
authored
19 years ago
by
deuce
Browse files
Options
Downloads
Patches
Plain Diff
Fix up return from realloc() handling.
parent
5365812d
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/xpdev/xpprintf.c
+19
-3
19 additions, 3 deletions
src/xpdev/xpprintf.c
with
19 additions
and
3 deletions
src/xpdev/xpprintf.c
+
19
−
3
View file @
7e614242
...
...
@@ -46,6 +46,7 @@ char *xp_asprintf_next(char *format, int type, ...)
unsigned
long
offset
=
0
;
size_t
format_len
;
size_t
this_format_len
;
size_t
tail_len
;
char
entry_buf
[
MAX_ARG_LEN
];
char
this_format
[
MAX_FORMAT_LEN
];
char
*
fmt
;
...
...
@@ -58,7 +59,7 @@ char *xp_asprintf_next(char *format, int type, ...)
for
(
p
=
format
;
*
p
;
p
++
)
{
if
(
*
p
==
'%'
)
{
if
(
*
(
p
+
1
)
==
'%'
)
p
+
=
2
;
p
+
+
;
else
break
;
}
...
...
@@ -111,9 +112,16 @@ char *xp_asprintf_next(char *format, int type, ...)
i
=
sprintf
(
entry_buf
,
"%u"
,
va_arg
(
vars
,
int
));
va_end
(
vars
);
if
(
i
>
1
)
{
/*
* We must calculate this before we go mucking about
* with format and p
*/
offset
=
p
-
format
;
newbuf
=
(
char
*
)
realloc
(
format
,
format_len
+
i
/* -1 for the '*' that's already there, +1 for the terminator */
);
if
(
newbuf
==
NULL
)
return
(
NULL
);
format
=
newbuf
;
p
=
format
+
offset
;
/*
* Move trailing end to make space... leaving the * where it
* is so it can be overwritten
...
...
@@ -140,9 +148,16 @@ char *xp_asprintf_next(char *format, int type, ...)
i
=
sprintf
(
entry_buf
,
"%u"
,
va_arg
(
vars
,
int
));
va_end
(
vars
);
if
(
i
>
1
)
{
/*
* We must calculate this before we go mucking about
* with format and p
*/
offset
=
p
-
format
;
newbuf
=
(
char
*
)
realloc
(
format
,
format_len
+
i
/* -1 for the '*' that's already there, +1 for the terminator */
);
if
(
newbuf
==
NULL
)
return
(
NULL
);
format
=
newbuf
;
p
=
format
+
offset
;
/*
* Move trailing end to make space... leaving the * where it
* is so it can be overwritten
...
...
@@ -289,9 +304,10 @@ char *xp_asprintf_next(char *format, int type, ...)
newbuf
=
(
char
*
)
realloc
(
format
,
format_len
-
this_format_len
+
j
+
1
);
if
(
newbuf
==
NULL
)
return
(
NULL
);
format
=
newbuf
;
/* Move trailing end to make space */
memmove
(
f
mt_start
+
j
,
fmt_star
t
+
this_format_len
,
format
-
fmt_star
t
+
format_len
-
this_format_len
+
1
);
memcpy
(
f
mt_star
t
,
entry_buf
,
j
);
memmove
(
f
ormat
+
offset
+
j
,
format
+
offse
t
+
this_format_len
,
offse
t
+
format_len
-
this_format_len
+
1
);
memcpy
(
f
ormat
+
offse
t
,
entry_buf
,
j
);
return
(
format
);
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment