mirror of
https://github.com/tezc/sc.git
synced 2025-02-04 07:13:10 +08:00
sc_uri: use snprintf instead of sprintf (#106)
This commit is contained in:
parent
2aabcc422f
commit
86a1574b79
@ -158,9 +158,10 @@ struct sc_uri *sc_uri_create(const char *str)
|
|||||||
fragment_len -= diff; // Skip "#"
|
fragment_len -= diff; // Skip "#"
|
||||||
fragment += diff; // Skip "#"
|
fragment += diff; // Skip "#"
|
||||||
|
|
||||||
ret = sprintf(dest, s2, scheme_len, scheme, 0, userinfo_len, userinfo,
|
ret = snprintf(dest, parts_len, s2, scheme_len, scheme, 0,
|
||||||
0, host_len, host, 0, port_len, port, 0, path_len, path,
|
userinfo_len, userinfo, 0, host_len, host, 0, port_len,
|
||||||
0, query_len, query, 0, fragment_len, fragment, 0);
|
port, 0, path_len, path, 0, query_len, query, 0,
|
||||||
|
fragment_len, fragment, 0);
|
||||||
if (ret < 0 || (size_t) ret != parts_len - 1) {
|
if (ret < 0 || (size_t) ret != parts_len - 1) {
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
@ -300,23 +300,6 @@ int __wrap_snprintf(char *str, size_t size, const char *format, ...)
|
|||||||
return fail_snprintf;
|
return fail_snprintf;
|
||||||
}
|
}
|
||||||
|
|
||||||
int fail_sprintf;
|
|
||||||
int __wrap_sprintf(char *str, const char *format, ...)
|
|
||||||
{
|
|
||||||
int rc;
|
|
||||||
va_list va;
|
|
||||||
|
|
||||||
if (!fail_sprintf) {
|
|
||||||
va_start(va, format);
|
|
||||||
rc = vsprintf(str, format, va);
|
|
||||||
va_end(va);
|
|
||||||
|
|
||||||
return rc;
|
|
||||||
}
|
|
||||||
|
|
||||||
return fail_sprintf;
|
|
||||||
}
|
|
||||||
|
|
||||||
void fail_test(void)
|
void fail_test(void)
|
||||||
{
|
{
|
||||||
struct sc_uri *uri;
|
struct sc_uri *uri;
|
||||||
@ -342,13 +325,13 @@ void fail_test(void)
|
|||||||
assert(sc_uri_create("tcp://127.0.0.1") == NULL);
|
assert(sc_uri_create("tcp://127.0.0.1") == NULL);
|
||||||
fail_snprintf = 0;
|
fail_snprintf = 0;
|
||||||
|
|
||||||
fail_sprintf = -1;
|
fail_snprintf = -1;
|
||||||
assert(sc_uri_create("tcp://127.0.0.1") == NULL);
|
assert(sc_uri_create("tcp://127.0.0.1") == NULL);
|
||||||
fail_sprintf = 0;
|
fail_snprintf = 0;
|
||||||
|
|
||||||
fail_sprintf = 1000000;
|
fail_snprintf = 1000000;
|
||||||
assert(sc_uri_create("tcp://127.0.0.1") == NULL);
|
assert(sc_uri_create("tcp://127.0.0.1") == NULL);
|
||||||
fail_sprintf = 0;
|
fail_snprintf = 0;
|
||||||
|
|
||||||
fail_strtoul = 1;
|
fail_strtoul = 1;
|
||||||
assert(sc_uri_create("tcp://127.0.0.1:9000") == NULL);
|
assert(sc_uri_create("tcp://127.0.0.1:9000") == NULL);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user