static char *locate_info(char *data, bool is_inner, bool is_class)
{
char *orig = data;
- char *locate = find_data(data);
+ char *locate;
if (!data)
return orig;
+ locate = find_data(data);
+ if (!locate)
+ return orig;
if (is_class)
return locate + 4;
if (!is_inner)
static int read_sys_node(char *where, char *save, size_t savesz)
{
char *new;
- int fd, ret = 0;
+ int fd, ret = 0, len;
fd = open(where, O_RDONLY);
if (fd < 0) {
fprintf(stderr, "Failed to open %s with errno %s\n",
return 1;
}
/* -1 so we can safely use strstr below */
- if(!read(fd, save, savesz - 1))
+ len = read(fd, save, savesz - 1);
+ if (!len)
ret = 1;
-
- new = strstr(save, "\n");
- if (new)
- new[0] = '\0';
-
+ else {
+ save[len] = '\0';
+ new = strstr(save, "\n");
+ if (new)
+ new[0] = '\0';
+ }
close(fd);
return ret;
}
continue;
if (is_top_level_match(line, vendor, false)) {
line[amnt - 1] = '\0';
+ free(device_top);
device_top = strdup(line);
parse_vendor_device(&line, file,
device,
error0:
fclose(file);
error1:
- return !line ? strdup("NULL") : strdup("Unknown Device");
+ return strdup("NULL");
}