mirror of
https://github.com/swaywm/sway.git
synced 2024-11-10 20:44:01 +01:00
Handle malloc failures from read_line
This commit is contained in:
parent
9ad1e6b40f
commit
4c6c65e70c
@ -1,4 +1,5 @@
|
||||
#include "readline.h"
|
||||
#include "log.h"
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
|
||||
@ -7,6 +8,7 @@ char *read_line(FILE *file) {
|
||||
char *string = malloc(size);
|
||||
char lastChar = '\0';
|
||||
if (!string) {
|
||||
sway_log(L_ERROR, "Unable to allocate memory for read_line");
|
||||
return NULL;
|
||||
}
|
||||
while (1) {
|
||||
@ -27,6 +29,7 @@ char *read_line(FILE *file) {
|
||||
char *new_string = realloc(string, size *= 2);
|
||||
if (!new_string) {
|
||||
free(string);
|
||||
sway_log(L_ERROR, "Unable to allocate memory for read_line");
|
||||
return NULL;
|
||||
}
|
||||
string = new_string;
|
||||
|
@ -575,6 +575,9 @@ bool read_config(FILE *file, struct sway_config *config) {
|
||||
char *line;
|
||||
while (!feof(file)) {
|
||||
line = read_line(file);
|
||||
if (!line) {
|
||||
continue;
|
||||
}
|
||||
line_number++;
|
||||
line = strip_whitespace(line);
|
||||
if (line[0] == '#') {
|
||||
|
15
sway/main.c
15
sway/main.c
@ -53,7 +53,10 @@ void detect_proprietary() {
|
||||
return;
|
||||
}
|
||||
while (!feof(f)) {
|
||||
char *line = read_line(f);
|
||||
char *line;
|
||||
if (!(line = read_line(f))) {
|
||||
break;
|
||||
}
|
||||
if (strstr(line, "nvidia")) {
|
||||
fprintf(stderr, "\x1B[1;31mWarning: Proprietary nvidia drivers do NOT support Wayland. Use nouveau.\x1B[0m\n");
|
||||
fprintf(stderr, "\x1B[1;31mYes, they STILL don't work with the newly announced wayland \"support\".\x1B[0m\n");
|
||||
@ -118,7 +121,10 @@ static void log_distro() {
|
||||
if (f) {
|
||||
sway_log(L_INFO, "Contents of %s:", paths[i]);
|
||||
while (!feof(f)) {
|
||||
char *line = read_line(f);
|
||||
char *line;
|
||||
if (!(line = read_line(f))) {
|
||||
break;
|
||||
}
|
||||
if (*line) {
|
||||
sway_log(L_INFO, "%s", line);
|
||||
}
|
||||
@ -136,7 +142,10 @@ static void log_kernel() {
|
||||
return;
|
||||
}
|
||||
while (!feof(f)) {
|
||||
char *line = read_line(f);
|
||||
char *line;
|
||||
if (!(line = read_line(f))) {
|
||||
break;
|
||||
}
|
||||
if (*line) {
|
||||
sway_log(L_INFO, "%s", line);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user