Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
V
vlc
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Redmine
Redmine
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Metrics
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
videolan
vlc
Commits
45b0f5c6
Commit
45b0f5c6
authored
Apr 09, 2009
by
Jean-Baptiste Kempf
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Revert "win32: vlc_fix_format_string - various fixes"
This reverts commit
3779d5bd
.
parent
ff3ff3ee
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
46 additions
and
48 deletions
+46
-48
include/vlc_fixups.h
include/vlc_fixups.h
+46
-48
No files found.
include/vlc_fixups.h
View file @
45b0f5c6
...
@@ -39,58 +39,56 @@ static inline char *strdup (const char *str)
...
@@ -39,58 +39,56 @@ static inline char *strdup (const char *str)
#endif
#endif
#ifdef WIN32
#ifdef WIN32
/* Windows' printf doesn't support %z modifiers, thus we need to rewrite
* the format string in a wrapper. */
# include <string.h>
# include <string.h>
# include <stdlib.h>
# include <stdlib.h>
/**
static
inline
char
*
vlc_fix_format_string
(
const
char
*
format
)
* vlc_fix_format_string:
* @format: address of format string to fix (format string is not modified)
*
* Windows' printf doesn't support %z size modifiers.
* Fix a *printf format string to make it safe for mingw/MSVCRT run times:
* %z* (not supported in MSVCRT) -> either %I64* or %I32.
*
* Returns: 1 if *format must be free()d; 0 otherwise
*/
static
inline
int
vlc_fix_format_string
(
const
char
**
format
)
{
{
int
n
=
0
;
char
*
fmt
;
const
char
*
tmp
=
*
format
;
# ifdef WIN64
while
((
tmp
=
strstr
(
tmp
,
"%z"
))
!=
NULL
)
const
char
*
src
=
format
,
*
tmp
;
char
*
dst
;
size_t
n
=
0
;
while
((
tmp
=
strstr
(
src
,
"%z"
))
!=
NULL
)
{
{
n
++
;
n
++
;
tmp
+=
2
;
src
=
tmp
+
2
;
}
}
if
(
!
n
)
if
(
n
==
0
)
return
0
;
return
NULL
;
char
*
dst
=
(
char
*
)
malloc
(
strlen
(
*
format
)
+
2
*
n
+
1
);
fmt
=
(
char
*
)
malloc
(
strlen
(
format
)
+
n
+
1
);
if
(
!
dst
)
if
(
fmt
==
NULL
)
{
return
NULL
;
*
format
=
"vlc_fix_format_string: due to malloc failure, unable to fix unsafe string"
;
return
0
;
}
const
char
*
src
=
*
format
;
src
=
format
;
*
format
=
ds
t
;
dst
=
fm
t
;
while
((
tmp
=
strstr
(
src
,
"%z"
))
!=
NULL
)
while
((
tmp
=
strstr
(
src
,
"%z"
))
!=
NULL
)
{
{
/* NB, don't use %l*, as this is buggy in mingw*/
size_t
d
=
tmp
-
src
;
size_t
d
=
tmp
-
src
;
memcpy
(
dst
,
src
,
d
);
memcpy
(
dst
,
src
,
d
);
dst
+=
d
;
dst
+=
d
;
*
dst
++
=
'%'
;
memcpy
(
dst
,
"%ll"
,
3
);
# ifdef WIN64
dst
+=
3
;
*
dst
++
=
'I'
;
*
dst
++
=
'6'
;
*
dst
++
=
'4'
;
# else
/* ie: WIN32 */
/* on win32, since the default size is 32bit, dont specify
* a modifer. (I32 isn't on wince, l doesn't work on mingw) */
# endif
src
=
tmp
+
2
;
src
=
tmp
+
2
;
}
}
strcpy
(
dst
,
src
);
strcpy
(
dst
,
src
);
return
1
;
# else
char
*
f
;
if
(
strstr
(
format
,
"%z"
)
==
NULL
)
return
NULL
;
fmt
=
strdup
(
format
);
if
(
fmt
==
NULL
)
return
NULL
;
while
((
f
=
strstr
(
fmt
,
"%z"
))
!=
NULL
)
{
f
[
1
]
=
'l'
;
}
# endif
return
fmt
;
}
}
# include <stdio.h>
# include <stdio.h>
...
@@ -98,40 +96,40 @@ static inline int vlc_fix_format_string (const char **format)
...
@@ -98,40 +96,40 @@ static inline int vlc_fix_format_string (const char **format)
static
inline
int
vlc_vprintf
(
const
char
*
format
,
va_list
ap
)
static
inline
int
vlc_vprintf
(
const
char
*
format
,
va_list
ap
)
{
{
int
must_free
=
vlc_fix_format_string
(
&
format
);
char
*
fmt
=
vlc_fix_format_string
(
format
);
int
ret
=
vprintf
(
format
,
ap
);
int
ret
=
vprintf
(
f
mt
?
fmt
:
f
ormat
,
ap
);
if
(
must_free
)
free
((
char
*
)
forma
t
);
free
(
fm
t
);
return
ret
;
return
ret
;
}
}
# define vprintf vlc_vprintf
# define vprintf vlc_vprintf
static
inline
int
vlc_vfprintf
(
FILE
*
stream
,
const
char
*
format
,
va_list
ap
)
static
inline
int
vlc_vfprintf
(
FILE
*
stream
,
const
char
*
format
,
va_list
ap
)
{
{
int
must_free
=
vlc_fix_format_string
(
&
format
);
char
*
fmt
=
vlc_fix_format_string
(
format
);
int
ret
=
vfprintf
(
stream
,
format
,
ap
);
int
ret
=
vfprintf
(
stream
,
f
mt
?
fmt
:
f
ormat
,
ap
);
if
(
must_free
)
free
((
char
*
)
forma
t
);
free
(
fm
t
);
return
ret
;
return
ret
;
}
}
# define vfprintf vlc_vfprintf
# define vfprintf vlc_vfprintf
static
inline
int
vlc_vsprintf
(
char
*
str
,
const
char
*
format
,
va_list
ap
)
static
inline
int
vlc_vsprintf
(
char
*
str
,
const
char
*
format
,
va_list
ap
)
{
{
int
must_free
=
vlc_fix_format_string
(
&
format
);
char
*
fmt
=
vlc_fix_format_string
(
format
);
int
ret
=
vsprintf
(
str
,
format
,
ap
);
int
ret
=
vsprintf
(
str
,
f
mt
?
fmt
:
f
ormat
,
ap
);
if
(
must_free
)
free
((
char
*
)
forma
t
);
free
(
fm
t
);
return
ret
;
return
ret
;
}
}
# define vsprintf vlc_vsprintf
# define vsprintf vlc_vsprintf
static
inline
int
vlc_vsnprintf
(
char
*
str
,
size_t
size
,
const
char
*
format
,
va_list
ap
)
static
inline
int
vlc_vsnprintf
(
char
*
str
,
size_t
size
,
const
char
*
format
,
va_list
ap
)
{
{
int
must_free
=
vlc_fix_format_string
(
&
format
);
char
*
fmt
=
vlc_fix_format_string
(
format
);
/* traditionally, MSVCRT has provided vsnprintf as _vsnprintf;
/* traditionally, MSVCRT has provided vsnprintf as _vsnprintf;
* to 'aid' portability/standards compliance, mingw provides a
* to 'aid' portability/standards compliance, mingw provides a
* static version of vsnprintf that is buggy. Be sure to use
* static version of vsnprintf that is buggy. Be sure to use
* MSVCRT version, at least it behaves as expected */
* MSVCRT version, at least it behaves as expected */
int
ret
=
_vsnprintf
(
str
,
size
,
format
,
ap
);
int
ret
=
_vsnprintf
(
str
,
size
,
f
mt
?
fmt
:
f
ormat
,
ap
);
if
(
must_free
)
free
((
char
*
)
forma
t
);
free
(
fm
t
);
return
ret
;
return
ret
;
}
}
# define vsnprintf vlc_vsnprintf
# define vsnprintf vlc_vsnprintf
...
...
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