mirror of
https://github.com/mirror/wget.git
synced 2025-01-05 09:50:27 +08:00
* src/url.c (append_uri_pathel): Replace alloca by fixed array / sprintf
This commit is contained in:
parent
c2d03b6293
commit
c0d8cceb93
31
src/res.c
31
src/res.c
@ -479,15 +479,6 @@ res_match_path (const struct robot_specs *specs, const char *path)
|
||||
|
||||
static struct hash_table *registered_specs;
|
||||
|
||||
/* Stolen from cookies.c. */
|
||||
#define SET_HOSTPORT(host, port, result) do { \
|
||||
int HP_len = strlen (host); \
|
||||
result = alloca (HP_len + 1 + numdigit (port) + 1); \
|
||||
memcpy (result, host, HP_len); \
|
||||
result[HP_len] = ':'; \
|
||||
number_to_string (result + HP_len + 1, port); \
|
||||
} while (0)
|
||||
|
||||
/* Register RES specs that below to server on HOST:PORT. They will
|
||||
later be retrievable using res_get_specs. */
|
||||
|
||||
@ -495,21 +486,27 @@ void
|
||||
res_register_specs (const char *host, int port, struct robot_specs *specs)
|
||||
{
|
||||
struct robot_specs *old;
|
||||
char *hp, *hp_old;
|
||||
SET_HOSTPORT (host, port, hp);
|
||||
char buf[256], *hp, *hp_old;
|
||||
|
||||
if (((unsigned) snprintf (buf, sizeof (buf), "%s:%d", host, port)) >= sizeof (buf))
|
||||
hp = aprintf("%s:%d", host, port);
|
||||
else
|
||||
hp = buf;
|
||||
|
||||
if (!registered_specs)
|
||||
registered_specs = make_nocase_string_hash_table (0);
|
||||
|
||||
if (hash_table_get_pair (registered_specs, hp, &hp_old, &old))
|
||||
{
|
||||
if (hp != buf)
|
||||
xfree (hp);
|
||||
if (old)
|
||||
free_specs (old);
|
||||
hash_table_put (registered_specs, hp_old, specs);
|
||||
}
|
||||
else
|
||||
{
|
||||
hash_table_put (registered_specs, xstrdup (hp), specs);
|
||||
hash_table_put (registered_specs, hp == buf ? xstrdup (hp) : hp, specs);
|
||||
}
|
||||
}
|
||||
|
||||
@ -518,10 +515,16 @@ res_register_specs (const char *host, int port, struct robot_specs *specs)
|
||||
struct robot_specs *
|
||||
res_get_specs (const char *host, int port)
|
||||
{
|
||||
char *hp;
|
||||
SET_HOSTPORT (host, port, hp);
|
||||
char buf[256], *hp;
|
||||
|
||||
if (!registered_specs)
|
||||
return NULL;
|
||||
|
||||
if (((unsigned) snprintf (buf, sizeof (buf), "%s:%d", host, port)) >= sizeof (buf))
|
||||
hp = aprintf("%s:%d", host, port);
|
||||
else
|
||||
hp = buf;
|
||||
|
||||
return hash_table_get (registered_specs, hp);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user