Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
git2
Overview
Overview
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
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
lvzhengyang
git2
Commits
84dd3820
Commit
84dd3820
authored
Aug 18, 2011
by
Vicent Marti
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
posix: Properly handle `snprintf` in all platforms
parent
c85e08b1
Hide whitespace changes
Inline
Side-by-side
Showing
12 changed files
with
30 additions
and
36 deletions
+30
-36
src/config.c
+1
-1
src/config_file.c
+4
-8
src/odb.c
+2
-4
src/pkt.c
+2
-1
src/reflog.c
+1
-1
src/remote.c
+3
-3
src/transport_local.c
+2
-1
src/unix/posix.h
+1
-0
src/util.c
+1
-15
src/util.h
+0
-2
src/win32/posix.c
+12
-0
src/win32/posix.h
+1
-0
No files found.
src/config.c
View file @
84dd3820
...
...
@@ -179,7 +179,7 @@ int git_config_delete(git_config *cfg, const char *name)
int
git_config_set_long
(
git_config
*
cfg
,
const
char
*
name
,
long
int
value
)
{
char
str_value
[
32
];
/* All numbers should fit in here */
snprintf
(
str_value
,
sizeof
(
str_value
),
"%ld"
,
value
);
p_
snprintf
(
str_value
,
sizeof
(
str_value
),
"%ld"
,
value
);
return
git_config_set_string
(
cfg
,
name
,
str_value
);
}
...
...
src/config_file.c
View file @
84dd3820
...
...
@@ -211,7 +211,7 @@ static int cvar_normalize_name(cvar_t *var, char **output)
/* If there aren't any spaces in the section, it's easy */
if
(
section_sp
==
NULL
)
{
ret
=
snprintf
(
name
,
len
+
1
,
"%s.%s"
,
var
->
section
,
var
->
name
);
ret
=
p_
snprintf
(
name
,
len
+
1
,
"%s.%s"
,
var
->
section
,
var
->
name
);
if
(
ret
<
0
)
{
free
(
name
);
return
git__throw
(
GIT_EOSERR
,
"Failed to normalize name. OS err: %s"
,
strerror
(
errno
));
...
...
@@ -672,12 +672,8 @@ static int parse_section_header_ext(const char *line, const char *base_name, cha
goto
out
;
}
ret
=
snprintf
(
*
section_name
,
total_len
,
"%s %s"
,
base_name
,
subsection
);
if
(
ret
>=
total_len
)
{
/* If this fails, we've checked the length wrong */
error
=
git__throw
(
GIT_ERROR
,
"Failed to parse ext header. Wrong total length calculation"
);
goto
out
;
}
else
if
(
ret
<
0
)
{
ret
=
p_snprintf
(
*
section_name
,
total_len
,
"%s %s"
,
base_name
,
subsection
);
if
(
ret
<
0
)
{
error
=
git__throw
(
GIT_EOSERR
,
"Failed to parse ext header. OS error: %s"
,
strerror
(
errno
));
goto
out
;
}
...
...
@@ -1140,7 +1136,7 @@ static int parse_multiline_variable(diskfile_backend *cfg, const char *first, ch
goto
out
;
}
ret
=
snprintf
(
buf
,
len
,
"%s %s"
,
first
,
line
);
ret
=
p_
snprintf
(
buf
,
len
,
"%s %s"
,
first
,
line
);
if
(
ret
<
0
)
{
error
=
git__throw
(
GIT_EOSERR
,
"Failed to parse multiline var. Failed to put together two lines. OS err: %s"
,
strerror
(
errno
));
free
(
buf
);
...
...
src/odb.c
View file @
84dd3820
...
...
@@ -49,13 +49,11 @@ typedef struct
static
int
format_object_header
(
char
*
hdr
,
size_t
n
,
size_t
obj_len
,
git_otype
obj_type
)
{
const
char
*
type_str
=
git_object_type2string
(
obj_type
);
int
len
=
snprintf
(
hdr
,
n
,
"%s %"
PRIuZ
,
type_str
,
obj_len
);
assert
(
len
>
0
);
/* otherwise snprintf() is broken */
assert
(((
size_t
)
len
)
<
n
);
/* otherwise the caller is broken! */
int
len
=
p_snprintf
(
hdr
,
n
,
"%s %"
PRIuZ
,
type_str
,
obj_len
);
if
(
len
<
0
||
((
size_t
)
len
)
>=
n
)
return
git__throw
(
GIT_ERROR
,
"Cannot format object header. Length is out of bounds"
);
return
len
+
1
;
}
...
...
src/pkt.c
View file @
84dd3820
...
...
@@ -33,6 +33,7 @@
#include "pkt.h"
#include "util.h"
#include "netops.h"
#include "posix.h"
#include <ctype.h>
...
...
@@ -285,7 +286,7 @@ static int send_want_with_caps(git_remote_head *head, git_transport_caps *caps,
git_oid_fmt
(
oid
,
&
head
->
oid
);
memset
(
cmd
,
0x0
,
len
+
1
);
snprintf
(
cmd
,
len
+
1
,
"%04xwant %s%c%s
\n
"
,
len
,
oid
,
0
,
capstr
);
p_
snprintf
(
cmd
,
len
+
1
,
"%04xwant %s%c%s
\n
"
,
len
,
oid
,
0
,
capstr
);
error
=
gitno_send
(
fd
,
cmd
,
len
,
0
);
free
(
cmd
);
return
error
;
...
...
src/reflog.c
View file @
84dd3820
...
...
@@ -254,7 +254,7 @@ int git_reflog_write(git_reference *ref, const git_oid *oid_old,
if
(
oid_old
)
git_oid_to_string
(
old
,
GIT_OID_HEXSZ
+
1
,
oid_old
);
else
snprintf
(
old
,
GIT_OID_HEXSZ
+
1
,
"%0*d"
,
GIT_OID_HEXSZ
,
0
);
p_
snprintf
(
old
,
GIT_OID_HEXSZ
+
1
,
"%0*d"
,
GIT_OID_HEXSZ
,
0
);
return
reflog_write
(
log_path
,
old
,
new
,
committer
,
msg
);
}
...
...
src/remote.c
View file @
84dd3820
...
...
@@ -100,7 +100,7 @@ int git_remote_get(git_remote **out, git_config *cfg, const char *name)
goto
cleanup
;
}
ret
=
snprintf
(
buf
,
buf_len
,
"%s.%s.%s"
,
"remote"
,
name
,
"url"
);
ret
=
p_
snprintf
(
buf
,
buf_len
,
"%s.%s.%s"
,
"remote"
,
name
,
"url"
);
if
(
ret
<
0
)
{
error
=
git__throw
(
GIT_EOSERR
,
"Failed to build config var name"
);
goto
cleanup
;
...
...
@@ -119,7 +119,7 @@ int git_remote_get(git_remote **out, git_config *cfg, const char *name)
goto
cleanup
;
}
ret
=
snprintf
(
buf
,
buf_len
,
"%s.%s.%s"
,
"remote"
,
name
,
"fetch"
);
ret
=
p_
snprintf
(
buf
,
buf_len
,
"%s.%s.%s"
,
"remote"
,
name
,
"fetch"
);
if
(
ret
<
0
)
{
error
=
git__throw
(
GIT_EOSERR
,
"Failed to build config var name"
);
goto
cleanup
;
...
...
@@ -131,7 +131,7 @@ int git_remote_get(git_remote **out, git_config *cfg, const char *name)
goto
cleanup
;
}
ret
=
snprintf
(
buf
,
buf_len
,
"%s.%s.%s"
,
"remote"
,
name
,
"push"
);
ret
=
p_
snprintf
(
buf
,
buf_len
,
"%s.%s.%s"
,
"remote"
,
name
,
"push"
);
if
(
ret
<
0
)
{
error
=
git__throw
(
GIT_EOSERR
,
"Failed to build config var name"
);
goto
cleanup
;
...
...
src/transport_local.c
View file @
84dd3820
...
...
@@ -7,6 +7,7 @@
#include "git2/tag.h"
#include "refs.h"
#include "transport.h"
#include "posix.h"
typedef
struct
{
git_transport
parent
;
...
...
@@ -93,7 +94,7 @@ static int add_ref(const char *name, git_repository *repo, git_vector *vec)
head
=
git__malloc
(
sizeof
(
git_remote_head
));
peel_len
=
strlen
(
name
)
+
STRLEN
(
peeled
);
head
->
name
=
git__malloc
(
peel_len
+
1
);
ret
=
snprintf
(
head
->
name
,
peel_len
+
1
,
"%s%s"
,
name
,
peeled
);
ret
=
p_
snprintf
(
head
->
name
,
peel_len
+
1
,
"%s%s"
,
name
,
peeled
);
if
(
ret
>=
peel_len
+
1
)
{
error
=
git__throw
(
GIT_ERROR
,
"The string is magically to long"
);
}
...
...
src/unix/posix.h
View file @
84dd3820
...
...
@@ -12,5 +12,6 @@
#define p_realpath(p, po) realpath(p, po)
#define p_fnmatch(p, s, f) fnmatch(p, s, f)
#define p_vsnprintf(b, c, f, a) vsnprintf(b, c, f, a)
#define p_snprintf(b, c, f, ...) snprintf(b, c, f, __VA_ARGS__)
#endif
src/util.c
View file @
84dd3820
...
...
@@ -118,19 +118,6 @@ Return:
return
GIT_SUCCESS
;
}
int
git__fmt
(
char
*
buf
,
size_t
buf_sz
,
const
char
*
fmt
,
...)
{
va_list
va
;
int
r
;
va_start
(
va
,
fmt
);
r
=
vsnprintf
(
buf
,
buf_sz
,
fmt
,
va
);
va_end
(
va
);
if
(
r
<
0
||
((
size_t
)
r
)
>=
buf_sz
)
return
git__throw
(
GIT_ERROR
,
"Failed to format string"
);
return
r
;
}
void
git__strntolower
(
char
*
str
,
int
len
)
{
int
i
;
...
...
@@ -367,4 +354,4 @@ int git__strcmp_cb(const void *a, const void *b)
const
char
*
strb
=
(
const
char
*
)
b
;
return
strcmp
(
stra
,
strb
);
}
\ No newline at end of file
}
src/util.h
View file @
84dd3820
...
...
@@ -66,8 +66,6 @@ GIT_INLINE(void *) git__realloc(void *ptr, size_t size)
return
new_ptr
;
}
extern
int
git__fmt
(
char
*
,
size_t
,
const
char
*
,
...)
GIT_FORMAT_PRINTF
(
3
,
4
);
extern
int
git__prefixcmp
(
const
char
*
str
,
const
char
*
prefix
);
extern
int
git__suffixcmp
(
const
char
*
str
,
const
char
*
suffix
);
...
...
src/win32/posix.c
View file @
84dd3820
...
...
@@ -218,3 +218,15 @@ int p_vsnprintf(char *buffer, size_t count, const char *format, va_list argptr)
return
vsnprintf
(
buffer
,
count
,
format
,
argptr
);
#endif
}
int
p_snprintf
(
char
*
buffer
,
size_t
count
,
const
char
*
format
,
...)
{
va_list
va
;
int
r
;
va_start
(
va
,
format
);
r
=
p_vsnprintf
(
buffer
,
count
,
format
,
va
);
va_end
(
va
);
return
r
;
}
src/win32/posix.h
View file @
84dd3820
...
...
@@ -24,5 +24,6 @@ extern int p_readlink(const char *link, char *target, size_t target_len);
extern
int
p_hide_directory__w32
(
const
char
*
path
);
extern
char
*
p_realpath
(
const
char
*
orig_path
,
char
*
buffer
);
extern
int
p_vsnprintf
(
char
*
buffer
,
size_t
count
,
const
char
*
format
,
va_list
argptr
);
extern
int
p_snprintf
(
char
*
buffer
,
size_t
count
,
const
char
*
format
,
...)
GIT_FORMAT_PRINTF
(
3
,
4
);
#endif
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