Replace fscanf(%as) by getline
The fscanf() have special %as conversion to auto-allocate buffer for the string. This is GNU extension and it's not implemented in uClibc. This leads to segmentation fault. So it was replaced by getline() function (POSIX.1-2008). Now it's more portable. Signed-off-by: Serj Kalichev <serj.kalichev@gmail.com> Signed-off-by: Neil Horman <nhorman@tuxdriver.com>
This commit is contained in:
parent
0930bf4592
commit
29ff67c301
16
classify.c
16
classify.c
|
@ -104,6 +104,8 @@ static struct irq_info *add_one_irq_to_db(const char *devpath, int irq)
|
||||||
FILE *fd;
|
FILE *fd;
|
||||||
char *lcpu_mask;
|
char *lcpu_mask;
|
||||||
GList *entry;
|
GList *entry;
|
||||||
|
ssize_t ret;
|
||||||
|
size_t blen;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* First check to make sure this isn't a duplicate entry
|
* First check to make sure this isn't a duplicate entry
|
||||||
|
@ -178,13 +180,12 @@ assign_node:
|
||||||
goto assign_affinity_hint;
|
goto assign_affinity_hint;
|
||||||
}
|
}
|
||||||
lcpu_mask = NULL;
|
lcpu_mask = NULL;
|
||||||
rc = fscanf(fd, "%as", &lcpu_mask);
|
ret = getline(&lcpu_mask, &blen, fd);
|
||||||
fclose(fd);
|
fclose(fd);
|
||||||
if (!lcpu_mask || !rc) {
|
if (ret <= 0) {
|
||||||
cpus_setall(new->cpumask);
|
cpus_setall(new->cpumask);
|
||||||
} else {
|
} else {
|
||||||
cpumask_parse_user(lcpu_mask, strlen(lcpu_mask),
|
cpumask_parse_user(lcpu_mask, ret, new->cpumask);
|
||||||
new->cpumask);
|
|
||||||
}
|
}
|
||||||
free(lcpu_mask);
|
free(lcpu_mask);
|
||||||
|
|
||||||
|
@ -195,12 +196,11 @@ assign_affinity_hint:
|
||||||
if (!fd)
|
if (!fd)
|
||||||
goto out;
|
goto out;
|
||||||
lcpu_mask = NULL;
|
lcpu_mask = NULL;
|
||||||
rc = fscanf(fd, "%as", &lcpu_mask);
|
ret = getline(&lcpu_mask, &blen, fd);
|
||||||
fclose(fd);
|
fclose(fd);
|
||||||
if (!lcpu_mask)
|
if (ret <= 0)
|
||||||
goto out;
|
goto out;
|
||||||
cpumask_parse_user(lcpu_mask, strlen(lcpu_mask),
|
cpumask_parse_user(lcpu_mask, ret, new->affinity_hint);
|
||||||
new->affinity_hint);
|
|
||||||
free(lcpu_mask);
|
free(lcpu_mask);
|
||||||
out:
|
out:
|
||||||
if (debug_mode)
|
if (debug_mode)
|
||||||
|
|
11
numa.c
11
numa.c
|
@ -55,9 +55,10 @@ static void add_one_node(const char *nodename)
|
||||||
{
|
{
|
||||||
char path[PATH_MAX];
|
char path[PATH_MAX];
|
||||||
struct topo_obj *new;
|
struct topo_obj *new;
|
||||||
char *cpustr;
|
char *cpustr = NULL;
|
||||||
FILE *f;
|
FILE *f;
|
||||||
int ret;
|
ssize_t ret;
|
||||||
|
size_t blen;
|
||||||
|
|
||||||
new = calloc(1, sizeof(struct topo_obj));
|
new = calloc(1, sizeof(struct topo_obj));
|
||||||
if (!new)
|
if (!new)
|
||||||
|
@ -67,11 +68,11 @@ static void add_one_node(const char *nodename)
|
||||||
if (ferror(f)) {
|
if (ferror(f)) {
|
||||||
cpus_clear(new->mask);
|
cpus_clear(new->mask);
|
||||||
} else {
|
} else {
|
||||||
ret = fscanf(f, "%as", &cpustr);
|
ret = getline(&cpustr, &blen, f);
|
||||||
if (!ret || !cpustr) {
|
if (ret <= 0) {
|
||||||
cpus_clear(new->mask);
|
cpus_clear(new->mask);
|
||||||
} else {
|
} else {
|
||||||
cpumask_parse_user(cpustr, strlen(cpustr), new->mask);
|
cpumask_parse_user(cpustr, ret, new->mask);
|
||||||
free(cpustr);
|
free(cpustr);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue