Skip to content

Commit

Permalink
Squash some GCC warnings that only appear when compiling with optimiz…
Browse files Browse the repository at this point in the history
…ation
  • Loading branch information
tbodt committed May 31, 2020
1 parent 9381dc2 commit e3c1346
Show file tree
Hide file tree
Showing 10 changed files with 23 additions and 12 deletions.
2 changes: 2 additions & 0 deletions emu/float80-test.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <math.h>
#include <fenv.h>
Expand Down Expand Up @@ -37,6 +38,7 @@ void _suite_start(const char *suite) {
case FE_DOWNWARD: rounding_mode_str = "down"; break;
case FE_UPWARD: rounding_mode_str = "up"; break;
case FE_TOWARDZERO: rounding_mode_str = "towards zero"; break;
default: abort();
}
printf("==== %s, round %s ====\n", suite, rounding_mode_str);
suite_passed = 0;
Expand Down
2 changes: 1 addition & 1 deletion emu/memory.c
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ void mem_next_page(struct mem *mem, page_t *page) {
}

page_t pt_find_hole(struct mem *mem, pages_t size) {
page_t hole_end;
page_t hole_end = 0; // this can never be used before initializing but gcc doesn't realize
bool in_hole = false;
for (page_t page = 0xf7ffd; page > 0x40000; page--) {
// I don't know how this works but it does
Expand Down
2 changes: 1 addition & 1 deletion fs/generic.c
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ int generic_getpath(struct fd *fd, char *buf) {
if (strlen(buf) + strlen(fd->mount->point) >= MAX_PATH)
return _ENAMETOOLONG;
memmove(buf + strlen(fd->mount->point), buf, strlen(buf) + 1);
strncpy(buf, fd->mount->point, strlen(fd->mount->point));
memcpy(buf, fd->mount->point, strlen(fd->mount->point));
if (buf[0] == '\0')
strcpy(buf, "/");
return 0;
Expand Down
3 changes: 2 additions & 1 deletion fs/lock.c
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,8 @@ static int file_lock_from_flock(struct fd *fd, struct flock_ *flock, struct file
offset = stat.size;
break;
}

default:
return _EINVAL;
}

lock->start = flock->start + offset;
Expand Down
1 change: 1 addition & 0 deletions fs/real.c
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,7 @@ int realfs_fsetattr(struct fd *fd, struct attr attr) {
case attr_size:
err = ftruncate(real_fd, attr.size);
break;
default: abort();
}
if (err < 0)
return errno_map();
Expand Down
2 changes: 1 addition & 1 deletion kernel/exec.c
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ static int elf_exec(struct fd *fd, const char *file, struct exec_args argv, stru

current->mm->exefile = fd_retain(fd);

addr_t load_addr; // used for AX_PHDR
addr_t load_addr = 0; // used for AX_PHDR
bool load_addr_set = false;
addr_t bias = 0; // offset for loading shared libraries as executables

Expand Down
2 changes: 1 addition & 1 deletion kernel/task.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ struct task {
#define MAX_GROUPS 32
unsigned ngroups;
uid_t_ groups[MAX_GROUPS];
char comm[16];
char comm[16] __strncpy_safe;
bool did_exec; // for that one annoying setsid edge case

struct fdtable *files;
Expand Down
7 changes: 7 additions & 0 deletions misc.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,14 @@
#define __no_instrument
#endif

#if is_gcc(8)
#define __strncpy_safe __attribute__((nonstring))
#else
#define __strncpy_safe
#endif

#define zero_init(type) ((type[1]){}[0])
#define pun(type, x) (((union {typeof(x) _; type a;}) (x)).a)

#define UNUSED(x) UNUSED_##x __attribute__((unused))
static inline void __use(int dummy __attribute__((unused)), ...) {}
Expand Down
8 changes: 4 additions & 4 deletions tools/ptraceomatic.c
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,8 @@ static int compare_cpus(struct cpu_state *cpu, struct tlb *tlb, int pid, int und
return -1;
}
#define CHECK_XMMREG(i) \
CHECK(*(uint64_t *) &fpregs.xmm_space[i * 4], cpu->xmm[i].qw[0], "xmm" #i " low") \
CHECK(*(uint64_t *) &fpregs.xmm_space[i*4+2], cpu->xmm[i].qw[1], "xmm" #i " high")
CHECK(pun(uint64_t, fpregs.xmm_space[i * 4]), cpu->xmm[i].qw[0], "xmm" #i " low") \
CHECK(pun(uint64_t, fpregs.xmm_space[i*4+2]), cpu->xmm[i].qw[1], "xmm" #i " high")
CHECK_XMMREG(0);
CHECK_XMMREG(1);
CHECK_XMMREG(2);
Expand All @@ -109,8 +109,8 @@ static int compare_cpus(struct cpu_state *cpu, struct tlb *tlb, int pid, int und
fpregs.swd &= FSW_MASK;

#define CHECK_FPREG(i) \
CHECK(*(uint64_t *) &fpregs.st_space[i * 4], cpu->fp[(cpu->top + i)%8].signif, "st(" #i ") signif") \
CHECK(*(uint16_t *) &fpregs.st_space[i*4+2], cpu->fp[(cpu->top + i)%8].signExp, "st(" #i ") sign/exp")
CHECK(pun(uint64_t, fpregs.st_space[i * 4]), cpu->fp[(cpu->top + i)%8].signif, "st(" #i ") signif") \
CHECK(pun(uint16_t, fpregs.st_space[i*4+2]), cpu->fp[(cpu->top + i)%8].signExp, "st(" #i ") sign/exp")
CHECK_FPREG(0);
CHECK_FPREG(1);
CHECK_FPREG(2);
Expand Down
6 changes: 3 additions & 3 deletions tools/undefined-flags.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ int undefined_flags_mask(struct cpu_state *cpu, struct tlb *tlb) {
case 0xac:
case 0xad: {
ip++;
byte_t shift;
byte_t shift = -1;
if (opcode == 0xad)
shift = cpu->cl;
else
Expand All @@ -52,7 +52,7 @@ int undefined_flags_mask(struct cpu_state *cpu, struct tlb *tlb) {
case 0xd2:
case 0xd3: {
ip++; // skip modrm
byte_t shift_count;
byte_t shift_count = -1;
if (opcode == 0xd0 || opcode == 0xd1)
shift_count = 1;
else if (opcode == 0xd2 || opcode == 0xd3)
Expand All @@ -66,7 +66,7 @@ int undefined_flags_mask(struct cpu_state *cpu, struct tlb *tlb) {

case 0xf6: case 0xf7: {
// group 3
byte_t modrm;
byte_t modrm = -1;
read(modrm);
switch (REG(modrm)) {
case 4: return S|Z|A|P; // mul
Expand Down

0 comments on commit e3c1346

Please sign in to comment.