Skip to content

Commit e8641ba

Browse files
committed
Fix error handling
1 parent 532f852 commit e8641ba

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

mrbgems/picoruby-machine/mrbgem.rake

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,3 @@ MRuby::Gem::Specification.new('picoruby-machine') do |spec|
99
cc.defines << "PICORB_PLATFORM_POSIX"
1010
end
1111
end
12-
13-

mrbgems/picoruby-machine/ports/posix/machine.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,16 @@ Machine_get_unique_id(char *id_str)
3434
{
3535
FILE *fp = fopen("/etc/machine-id", "r");
3636
if (fp) {
37-
fgets(id_str, 32, fp);
37+
if (fgets(id_str, 32, fp) == NULL) {
38+
perror("Failed to read /etc/machine-id");
39+
fclose(fp);
40+
return false;
41+
}
3842
fclose(fp);
39-
} else {
40-
perror("Failed to open /etc/machine-id");
43+
return true;
4144
}
42-
return true;
45+
perror("Failed to open /etc/machine-id");
46+
return false;
4347
}
4448

4549
uint32_t

0 commit comments

Comments
 (0)