LibC+userspace: Make everything compile with -Wall -Wextra -Werror
I added -Wall -Wextra -Werror as public compile flags to libc. Now everything in userspace in compiled using these flags. I made all necessary changes to allow compilation to work. Only exception is execvp which has a large stack usage. Maybe it should use malloc for the buffer but posix allows ENOMEM only when kernel is out of memory... This can be fixed when fexecve is implemented and there is no need for absolute path.
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
#include <BAN/Vector.h>
|
||||
|
||||
#include <ctype.h>
|
||||
#include <inttypes.h>
|
||||
#include <stdio.h>
|
||||
#include <stdint.h>
|
||||
|
||||
@@ -85,13 +86,13 @@ BAN::Array<Position, 2> find_grid_first_moves(const Grid& grid)
|
||||
if (grid[y][x] == 'S')
|
||||
{
|
||||
size_t index = 0;
|
||||
if (can_enter_tile_from(grid[y - 1][x], Direction::South))
|
||||
if (index < 2 && can_enter_tile_from(grid[y - 1][x], Direction::South))
|
||||
positions[index++] = { x, y - 1, Direction::South };
|
||||
if (can_enter_tile_from(grid[y + 1][x], Direction::North))
|
||||
if (index < 2 && can_enter_tile_from(grid[y + 1][x], Direction::North))
|
||||
positions[index++] = { x, y + 1, Direction::North };
|
||||
if (can_enter_tile_from(grid[y][x - 1], Direction::East))
|
||||
if (index < 2 && can_enter_tile_from(grid[y][x - 1], Direction::East))
|
||||
positions[index++] = { x - 1, y, Direction::East };
|
||||
if (can_enter_tile_from(grid[y][x + 1], Direction::West))
|
||||
if (index < 2 && can_enter_tile_from(grid[y][x + 1], Direction::West))
|
||||
positions[index++] = { x + 1, y, Direction::West };
|
||||
ASSERT(index == 2);
|
||||
return positions;
|
||||
@@ -268,11 +269,11 @@ int main(int argc, char** argv)
|
||||
return 1;
|
||||
}
|
||||
|
||||
printf("puzzle1: %lld\n", puzzle1(fp));
|
||||
printf("puzzle1: %" PRId64 "\n", puzzle1(fp));
|
||||
|
||||
fseek(fp, 0, SEEK_SET);
|
||||
|
||||
printf("puzzle2: %lld\n", puzzle2(fp));
|
||||
printf("puzzle2: %" PRId64 "\n", puzzle2(fp));
|
||||
|
||||
fclose(fp);
|
||||
}
|
||||
|
||||
@@ -64,7 +64,7 @@ int puzzle2(FILE* fp)
|
||||
continue;
|
||||
ptr += 5;
|
||||
|
||||
int id = parse_int_and_advance(ptr);
|
||||
parse_int_and_advance(ptr);
|
||||
ptr += 2;
|
||||
|
||||
int needed_red = 0;
|
||||
|
||||
@@ -21,9 +21,9 @@ int puzzle1(FILE* fp)
|
||||
|
||||
int result = 0;
|
||||
|
||||
for (ssize_t y = 0; y < lines.size(); y++)
|
||||
for (size_t y = 0; y < lines.size(); y++)
|
||||
{
|
||||
for (ssize_t x = 0; x < lines[y].size(); x++)
|
||||
for (size_t x = 0; x < lines[y].size(); x++)
|
||||
{
|
||||
if (!isdigit(lines[y][x]))
|
||||
continue;
|
||||
@@ -32,14 +32,14 @@ int puzzle1(FILE* fp)
|
||||
|
||||
for (ssize_t y_off = -1; y_off <= 1; y_off++)
|
||||
{
|
||||
if (y + y_off < 0)
|
||||
if ((ssize_t)y < y_off)
|
||||
continue;
|
||||
if (y + y_off >= lines.size())
|
||||
break;
|
||||
|
||||
for (ssize_t x_off = -1;; x_off++)
|
||||
{
|
||||
if (x + x_off < 0)
|
||||
if ((ssize_t)x < x_off)
|
||||
continue;
|
||||
if (x + x_off >= lines[y + y_off].size())
|
||||
break;
|
||||
@@ -94,9 +94,9 @@ int puzzle2(FILE* fp)
|
||||
// Map numbers next to '*' to asterisk's coordinates.
|
||||
HashMap<uint32_t, Vector<int>> gears;
|
||||
|
||||
for (ssize_t y = 0; y < lines.size(); y++)
|
||||
for (size_t y = 0; y < lines.size(); y++)
|
||||
{
|
||||
for (ssize_t x = 0; x < lines[y].size(); x++)
|
||||
for (size_t x = 0; x < lines[y].size(); x++)
|
||||
{
|
||||
if (!isdigit(lines[y][x]))
|
||||
continue;
|
||||
@@ -111,14 +111,14 @@ int puzzle2(FILE* fp)
|
||||
|
||||
for (ssize_t y_off = -1; y_off <= 1; y_off++)
|
||||
{
|
||||
if (y + y_off < 0)
|
||||
if ((ssize_t)y < y_off)
|
||||
continue;
|
||||
if (y + y_off >= lines.size())
|
||||
break;
|
||||
|
||||
for (ssize_t x_off = -1;; x_off++)
|
||||
{
|
||||
if (x + x_off < 0)
|
||||
if ((ssize_t)x < x_off)
|
||||
continue;
|
||||
if (x + x_off >= lines[y + y_off].size())
|
||||
break;
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#include <BAN/HashMap.h>
|
||||
#include <BAN/Vector.h>
|
||||
|
||||
#include <inttypes.h>
|
||||
#include <stdio.h>
|
||||
|
||||
using i64 = int64_t;
|
||||
@@ -31,7 +32,7 @@ i64 puzzle1(FILE* fp)
|
||||
line = line.substring(0, line.size() - 1);
|
||||
|
||||
auto seeds_str = MUST(line.split(' '));
|
||||
for (i64 i = 1; i < seeds_str.size(); i++)
|
||||
for (size_t i = 1; i < seeds_str.size(); i++)
|
||||
MUST(current.emplace_back(parse_i64(seeds_str[i]), 0));
|
||||
}
|
||||
|
||||
@@ -92,7 +93,7 @@ i64 puzzle2(FILE* fp)
|
||||
BAN::StringView line(buffer);
|
||||
line = line.substring(0, line.size() - 1);
|
||||
auto seeds_str = MUST(line.split(' '));
|
||||
for (i64 i = 1; i < seeds_str.size(); i += 2)
|
||||
for (size_t i = 1; i < seeds_str.size(); i += 2)
|
||||
MUST(current.emplace_back(parse_i64(seeds_str[i]), parse_i64(seeds_str[i + 1]), 0));
|
||||
}
|
||||
|
||||
@@ -179,11 +180,11 @@ int main(int argc, char** argv)
|
||||
return 1;
|
||||
}
|
||||
|
||||
printf("puzzle1: %lld\n", puzzle1(fp));
|
||||
printf("puzzle1: %" PRId64 "\n", puzzle1(fp));
|
||||
|
||||
fseek(fp, 0, SEEK_SET);
|
||||
|
||||
printf("puzzle2: %lld\n", puzzle2(fp));
|
||||
printf("puzzle2: %" PRId64 "\n", puzzle2(fp));
|
||||
|
||||
fclose(fp);
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#include <BAN/Vector.h>
|
||||
|
||||
#include <ctype.h>
|
||||
#include <inttypes.h>
|
||||
#include <stdio.h>
|
||||
#include <stdint.h>
|
||||
|
||||
@@ -112,11 +113,11 @@ int main(int argc, char** argv)
|
||||
return 1;
|
||||
}
|
||||
|
||||
printf("puzzle1: %lld\n", puzzle1(fp));
|
||||
printf("puzzle1: %" PRId64 "\n", puzzle1(fp));
|
||||
|
||||
fseek(fp, 0, SEEK_SET);
|
||||
|
||||
printf("puzzle2: %lld\n", puzzle2(fp));
|
||||
printf("puzzle1: %" PRId64 "\n", puzzle2(fp));
|
||||
|
||||
fclose(fp);
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
#include <BAN/String.h>
|
||||
|
||||
#include <ctype.h>
|
||||
#include <inttypes.h>
|
||||
#include <stdio.h>
|
||||
#include <stdint.h>
|
||||
|
||||
@@ -142,11 +143,11 @@ int main(int argc, char** argv)
|
||||
return 1;
|
||||
}
|
||||
|
||||
printf("puzzle1: %lld\n", puzzle(fp, false));
|
||||
printf("puzzle1: %" PRId64 "\n", puzzle(fp, false));
|
||||
|
||||
fseek(fp, 0, SEEK_SET);
|
||||
|
||||
printf("puzzle2: %lld\n", puzzle(fp, true));
|
||||
printf("puzzle2: %" PRId64 "\n", puzzle(fp, true));
|
||||
|
||||
fclose(fp);
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
#include <BAN/String.h>
|
||||
|
||||
#include <ctype.h>
|
||||
#include <inttypes.h>
|
||||
#include <stdio.h>
|
||||
#include <stdint.h>
|
||||
|
||||
@@ -121,11 +122,11 @@ int main(int argc, char** argv)
|
||||
return 1;
|
||||
}
|
||||
|
||||
printf("puzzle1: %lld\n", puzzle1(fp));
|
||||
printf("puzzle1: %" PRId64 "\n", puzzle1(fp));
|
||||
|
||||
fseek(fp, 0, SEEK_SET);
|
||||
|
||||
printf("puzzle2: %lld\n", puzzle2(fp));
|
||||
printf("puzzle2: %" PRId64 "\n", puzzle2(fp));
|
||||
|
||||
fclose(fp);
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
#include <BAN/Vector.h>
|
||||
|
||||
#include <ctype.h>
|
||||
#include <inttypes.h>
|
||||
#include <stdio.h>
|
||||
#include <stdint.h>
|
||||
|
||||
@@ -114,11 +115,11 @@ int main(int argc, char** argv)
|
||||
return 1;
|
||||
}
|
||||
|
||||
printf("puzzle1: %lld\n", puzzle1(fp));
|
||||
printf("puzzle1: %" PRId64 "\n", puzzle1(fp));
|
||||
|
||||
fseek(fp, 0, SEEK_SET);
|
||||
|
||||
printf("puzzle2: %lld\n", puzzle2(fp));
|
||||
printf("puzzle2: %" PRId64 "\n", puzzle2(fp));
|
||||
|
||||
fclose(fp);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user