Fix env parsing code
Also changed the separator to comma instead of colon.
This commit is contained in:
parent
3931837beb
commit
c4d63ef744
@ -62,28 +62,44 @@ static const struct hb_shaper_pair_t {
|
|||||||
|
|
||||||
static class static_shaper_list_t {
|
static class static_shaper_list_t {
|
||||||
public:
|
public:
|
||||||
static_shaper_list_t (void) {
|
static_shaper_list_t (void)
|
||||||
|
{
|
||||||
char *env = getenv ("HB_SHAPER_LIST");
|
char *env = getenv ("HB_SHAPER_LIST");
|
||||||
shaper_list = NULL;
|
shaper_list = NULL;
|
||||||
if (!env || !*env)
|
if (!env || !*env)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
unsigned int count = 3; /* initial, fallback, null */
|
unsigned int count = 3; /* initial, fallback, null */
|
||||||
for (const char *p = env; (p == strchr (p, ':')) && p++; )
|
for (const char *p = env; (p == strchr (p, ',')) && p++; )
|
||||||
count++;
|
count++;
|
||||||
if (count <= ARRAY_LENGTH (static_shaper_list))
|
|
||||||
shaper_list = static_shaper_list;
|
unsigned int len = strlen (env);
|
||||||
else
|
|
||||||
shaper_list = (const char **) malloc (count * sizeof (shaper_list[0]));
|
if (count > 100 || len > 1000)
|
||||||
|
return;
|
||||||
|
|
||||||
|
len += count * sizeof (*shaper_list) + 1;
|
||||||
|
char *buffer = len < sizeof (static_buffer) ? static_buffer : (char *) malloc (len);
|
||||||
|
shaper_list = (const char **) buffer;
|
||||||
|
buffer += count * sizeof (*shaper_list);
|
||||||
|
len -= count * sizeof (*shaper_list);
|
||||||
|
strncpy (buffer, env, len);
|
||||||
|
|
||||||
count = 0;
|
count = 0;
|
||||||
shaper_list[count++] = env;
|
shaper_list[count++] = buffer;
|
||||||
for (char *p = env; (p == strchr (p, ':')) && (*p = '\0', TRUE) && p++; )
|
for (char *p = buffer; (p == strchr (p, ',')) && (*p = '\0', TRUE) && p++; )
|
||||||
shaper_list[count++] = p;
|
shaper_list[count++] = p;
|
||||||
shaper_list[count++] = "fallback";
|
shaper_list[count++] = "fallback";
|
||||||
shaper_list[count] = NULL;
|
shaper_list[count] = NULL;
|
||||||
}
|
}
|
||||||
|
~static_shaper_list_t (void)
|
||||||
|
{
|
||||||
|
if ((char *) shaper_list != static_buffer)
|
||||||
|
free (shaper_list);
|
||||||
|
}
|
||||||
|
|
||||||
const char **shaper_list;
|
const char **shaper_list;
|
||||||
const char *static_shaper_list[10];
|
char static_buffer[32];
|
||||||
} env_shaper_list;
|
} env_shaper_list;
|
||||||
|
|
||||||
hb_bool_t
|
hb_bool_t
|
||||||
|
Loading…
Reference in New Issue
Block a user