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;
|
||||
char *lcpu_mask;
|
||||
GList *entry;
|
||||
ssize_t ret;
|
||||
size_t blen;
|
||||
|
||||
/*
|
||||
* First check to make sure this isn't a duplicate entry
|
||||
|
@ -178,13 +180,12 @@ assign_node:
|
|||
goto assign_affinity_hint;
|
||||
}
|
||||
lcpu_mask = NULL;
|
||||
rc = fscanf(fd, "%as", &lcpu_mask);
|
||||
ret = getline(&lcpu_mask, &blen, fd);
|
||||
fclose(fd);
|
||||
if (!lcpu_mask || !rc) {
|
||||
if (ret <= 0) {
|
||||
cpus_setall(new->cpumask);
|
||||
} else {
|
||||
cpumask_parse_user(lcpu_mask, strlen(lcpu_mask),
|
||||
new->cpumask);
|
||||
cpumask_parse_user(lcpu_mask, ret, new->cpumask);
|
||||
}
|
||||
free(lcpu_mask);
|
||||
|
||||
|
@ -195,12 +196,11 @@ assign_affinity_hint:
|
|||
if (!fd)
|
||||
goto out;
|
||||
lcpu_mask = NULL;
|
||||
rc = fscanf(fd, "%as", &lcpu_mask);
|
||||
ret = getline(&lcpu_mask, &blen, fd);
|
||||
fclose(fd);
|
||||
if (!lcpu_mask)
|
||||
if (ret <= 0)
|
||||
goto out;
|
||||
cpumask_parse_user(lcpu_mask, strlen(lcpu_mask),
|
||||
new->affinity_hint);
|
||||
cpumask_parse_user(lcpu_mask, ret, new->affinity_hint);
|
||||
free(lcpu_mask);
|
||||
out:
|
||||
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];
|
||||
struct topo_obj *new;
|
||||
char *cpustr;
|
||||
char *cpustr = NULL;
|
||||
FILE *f;
|
||||
int ret;
|
||||
ssize_t ret;
|
||||
size_t blen;
|
||||
|
||||
new = calloc(1, sizeof(struct topo_obj));
|
||||
if (!new)
|
||||
|
@ -67,11 +68,11 @@ static void add_one_node(const char *nodename)
|
|||
if (ferror(f)) {
|
||||
cpus_clear(new->mask);
|
||||
} else {
|
||||
ret = fscanf(f, "%as", &cpustr);
|
||||
if (!ret || !cpustr) {
|
||||
ret = getline(&cpustr, &blen, f);
|
||||
if (ret <= 0) {
|
||||
cpus_clear(new->mask);
|
||||
} else {
|
||||
cpumask_parse_user(cpustr, strlen(cpustr), new->mask);
|
||||
cpumask_parse_user(cpustr, ret, new->mask);
|
||||
free(cpustr);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue