Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes to build on Ubuntu 18.04 with gcc-9.4 #105

Open
wants to merge 34 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
b62beeb
Fixes to build on Ubuntu 18.04 with gcc-9.4
mingodad Feb 20, 2024
5f3a9b3
Check for pointer validity before use
mingodad Feb 21, 2024
f7d5b4c
Applied latest changes from origin/main and fix some compiler warnings
mingodad Feb 21, 2024
0ebaf7c
Fix compiler warning on free(textfile) by removing the "const" qualifier
mingodad Feb 21, 2024
fed1c01
Add a wrapper around "system" and "chdir" to print the passed parameter
mingodad Feb 21, 2024
c1bf5d7
Fix compiler warning about possible buffer overflow
mingodad Feb 21, 2024
9b89496
Attempt to fix buffer overflow on linux due to use MAX_PATH instead o…
mingodad Feb 21, 2024
e64ae41
Add latest fixes from origin/main
mingodad Feb 21, 2024
036ebce
Add an option to dump the tokens from the tokenizer
mingodad Feb 21, 2024
91ee639
Fix several missing token names, but there is more to be done
mingodad Feb 21, 2024
7bdd85d
Add the latest changes from origin/main
mingodad Feb 22, 2024
b5700c9
Fix cake warnings
mingodad Feb 22, 2024
a876cd2
Fix use after free detected by valgrind
mingodad Feb 22, 2024
c19d7bc
Change the fix for the previous commit about use after free
mingodad Feb 23, 2024
b76d4f3
Partial fix for use of non checked "p_expression_node->right".
mingodad Feb 23, 2024
08d680c
Partial fix for the usage of "realpath" that can fail, we need a bett…
mingodad Feb 23, 2024
0211995
Fixes to go farther when parsing sqlite3.c
mingodad Feb 23, 2024
6ac91ab
Add an option to dump the tokens after preprocessing, also added a al…
mingodad Feb 23, 2024
9294ae7
Temporary fix to parse "va_arg"
mingodad Feb 23, 2024
d74e3e9
Changes to give a bit better output for type mismatch errors
mingodad Feb 23, 2024
603abc4
Fix to parse "wchar_t" literals type
mingodad Feb 23, 2024
a4bcf34
Fix calling "type_remove_pointer" on non pointers
mingodad Feb 23, 2024
5e61573
Fix user after free
mingodad Feb 23, 2024
0a59d95
Fix use after free and temporary skip _Geeric parameter name when it'…
mingodad Feb 23, 2024
3c87940
Add changes from origin/main
mingodad Feb 24, 2024
aa07dbd
Fix UTF8 assert range
mingodad Feb 24, 2024
8a60839
Add changes from origin/main
mingodad Feb 25, 2024
b3c7c11
Fix memory use after free
mingodad Feb 25, 2024
259da20
Attempt to fix endless loop when including system inculdes by not sea…
mingodad Feb 25, 2024
b429420
Fixes to fix use after free detected by valgrind while trying to pars…
mingodad Feb 25, 2024
49e37b1
Applied some changes from origin/main
mingodad Feb 25, 2024
9bde198
Fixes to memory errors detected by valgrind while testing on tinycc r…
mingodad Feb 25, 2024
cf98e51
Apply some changes from origin/main
mingodad Feb 25, 2024
878b935
This fix/hide a memory problem detected by valgrind while testing cpp…
mingodad Feb 25, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1,206 changes: 1,206 additions & 0 deletions docs/cakeEBNn3096.txt

Large diffs are not rendered by default.

200 changes: 102 additions & 98 deletions manual.md

Large diffs are not rendered by default.

20 changes: 20 additions & 0 deletions mk-it.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/bin/sh
cwd=$PWD
cd src
#gcc-13-env
gcc -g build.c -o build && ./build
#emsdk-env emcc -Wno-multichar -DMOCKFILES "lib.c" -o "web\cake.js" -s WASM=0 -s EXPORTED_FUNCTIONS=_CompileText -s EXPORTED_RUNTIME_METHODS=ccall,cwrap
cd $cwd
#myvalgrind src/cake -Iinclude /home/mingo/dev/dadbiz++/third-party/dad/sqlite3-orig/sqlite3.c
#myvalgrind ./cake -E /home/mingo/dev/dadbiz++/third-party/dad/sqlite3-orig/sqlite3.c
#./cake -analyze -D__x86_64__ -I/usr/lib/gcc/x86_64-linux-gnu/11/include/ -I/usr/local/include/ -I/usr/include/x86_64-linux-gnu/ -I/usr/include/ console.h tokenizer.h parser.h error.h fs.h hash.h object.h hashmap.h osstream.h options.h token.h type.h pre_expressions.h expressions.h visit.h format_visit.h token.c hash.c hashmap.c console.c tokenizer.c osstream.c fs.c options.c expressions.c pre_expressions.c type.c object.c parser.c visit.c flow_visit.c error.c format_visit.c tests.c
#./cake -analyze -I/usr/lib/gcc/x86_64-linux-gnu/11/include/ -I/usr/local/include/ -I/usr/include/x86_64-linux-gnu/ -I/usr/include/ console.c
#myvalgrind --vgdb-error=0 src/cake -Iinclude /home/mingo/dev/dadbiz++/third-party/dad/sqlite3-orig/sqlite3.c
#myvalgrind src/cake -Iinclude dad/test-va.c
#src/cake -dump-tokens dad/test-inf-nan.c
#src/cake -dump-tokens dad/test-wchar.c
#src/cake dad/test-type-pointer.c
#src/cake dad/test-align.c
#src/cake dad/test-double-free.c
#src/cake dad/test-generic.c
#src/cake dad/test-trigraph.c
6 changes: 5 additions & 1 deletion ownership.md
Original file line number Diff line number Diff line change
Expand Up @@ -1023,7 +1023,11 @@ int main()


**Rule:** Arguments must be valid.


Exception

`malloc` and `calloc` have built in semantics.


**Listing 35 - Function Arguments cannot be in a moved or uninitialized state**

Expand Down
70 changes: 42 additions & 28 deletions src/build.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,20 @@

#include "build.h"

static int mysytem(const char *cmd)
{
printf("%s\n", cmd);
fflush(stdout);
return system(cmd);
}

static int mychdir(const char *path)
{
printf("chdir: %s\n", path);
fflush(stdout);
return chdir(path);
}

#ifdef BUILD_WINDOWS
#define OUTPUT "cake.exe"
#else
Expand All @@ -30,8 +44,8 @@
" pre_expressions.h " \
" expressions.h " \
" visit.h " \
" format_visit.h "
" format_visit.h "


#define SOURCE_FILES \
" token.c " \
Expand All @@ -52,13 +66,13 @@
" error.c " \
" format_visit.c " \
" tests.c "


void compile_cake()
{

#ifdef BUILD_WINDOWS_MSC
if (system("cl " SOURCE_FILES " main.c "
if (mysytem("cl " SOURCE_FILES " main.c "

#ifdef DISABLE_COLORS
" /DDISABLE_COLORS "
Expand Down Expand Up @@ -106,7 +120,7 @@ void compile_cake()

#ifdef BUILD_WINDOWS_CLANG

system("clang " SOURCE_FILES " main.c "
mysytem("clang " SOURCE_FILES " main.c "
#if defined DEBUG
" -D_DEBUG"
#else
Expand All @@ -129,7 +143,7 @@ void compile_cake()
#endif

#ifdef BUILD_LINUX_CLANG
system("clang " SOURCE_FILES " main.c "
mysytem("clang " SOURCE_FILES " main.c "
#ifdef TEST
"-DTEST"
#endif
Expand All @@ -141,11 +155,10 @@ void compile_cake()
#if defined BUILD_LINUX_GCC || defined BUILD_WINDOWS_GCC

// #define GCC_ANALIZER " -fanalyzer "
system("gcc "
mysytem("gcc "
" -Wall "
" -Wno-multichar "
" -Wno-switch "
" -g " SOURCE_FILES " main.c "
" -g -O2 " SOURCE_FILES " main.c "

#if defined DEBUG
" -D_DEBUG"
Expand All @@ -160,7 +173,7 @@ void compile_cake()
#endif

#ifdef BUILD_WINDOWS_TCC
system(CC
mysytem(CC
SOURCE_FILES " main.c "

#if defined DEBUG
Expand Down Expand Up @@ -204,11 +217,11 @@ void generate_doc(const char *mdfilename, const char *outfile)
}
char cmd[200];
snprintf(cmd, sizeof cmd, RUN "hoedown.exe --html-toc --toc-level 3 --autolink --fenced-code %s >> %s", mdfilename, outfile);
if (system(cmd) != 0)
if (mysytem(cmd) != 0)
exit(1);

snprintf(cmd, sizeof cmd, RUN "hoedown.exe --toc-level 3 --autolink --fenced-code %s >> %s", mdfilename, outfile);
if (system(cmd) != 0)
if (mysytem(cmd) != 0)
exit(1);

FILE *f3 = fopen(outfile /*"./web/index.html"*/, "a");
Expand All @@ -229,22 +242,22 @@ int main()
#endif

printf("Building tools-------------------------------------------\n");
chdir("./tools");
mychdir("./tools");

if (system(CC " -D_CRT_SECURE_NO_WARNINGS maketest.c " OUT_OPT "../maketest.exe") != 0)
if (mysytem(CC " -D_CRT_SECURE_NO_WARNINGS maketest.c " OUT_OPT "../maketest.exe") != 0)
exit(1);
if (system(CC " -D_CRT_SECURE_NO_WARNINGS amalgamator.c " OUT_OPT "../amalgamator.exe") != 0)
if (mysytem(CC " -D_CRT_SECURE_NO_WARNINGS amalgamator.c " OUT_OPT "../amalgamator.exe") != 0)
exit(1);

chdir("./hoedown");
mychdir("./hoedown");

#define HOEDOWN_SRC " autolink.c buffer.c document.c escape.c hoedown.c html.c html_blocks.c html_smartypants.c stack.c version.c"

if (system(CC HOEDOWN_SRC OUT_OPT "../../hoedown.exe") != 0)
if (mysytem(CC HOEDOWN_SRC OUT_OPT "../../hoedown.exe") != 0)
exit(1);

chdir("..");
chdir("..");
mychdir("..");
mychdir("..");

/*
* Generates documentation from md files
Expand All @@ -254,15 +267,15 @@ int main()
generate_doc("../README.md", "./web/index.html");
generate_doc("../warnings.md", "./web/warnings.html");
generate_doc("../ownership.md", "./web/ownership.html");


remove("hoedown.exe");

if (system(RUN "maketest.exe unit_test.c " SOURCE_FILES) != 0)
if (mysytem(RUN "maketest.exe unit_test.c " SOURCE_FILES) != 0)
exit(1);
remove("maketest.exe");

if (system(RUN "amalgamator.exe -olib.c" SOURCE_FILES) != 0)
if (mysytem(RUN "amalgamator.exe -olib.c" SOURCE_FILES) != 0)
exit(1);
remove("amalgamator.exe");

Expand All @@ -277,30 +290,31 @@ int main()
running cake on its own source code
*/

//-flow-analysis
//-flow-analysis
//-nullchecks
#ifdef NULLCHECKS
#define NC " -nullchecks "
#else
#define NC " "
#endif

if (system("cake.exe " NC " -Wstyle -analyze -Wno-unused-parameter -Wno-unused-variable -sarif " HEADER_FILES SOURCE_FILES) != 0)
if (mysytem("cake.exe " NC " -Wstyle -analyze -Wno-unused-parameter -Wno-unused-variable -sarif " HEADER_FILES SOURCE_FILES) != 0)
exit(1);
#endif

#if defined BUILD_LINUX_GCC
/*
running cake on its own source code
To find GCC directories use
To find GCC directories use
echo | gcc -E -Wp,-v -
*/
if (system("./cake "
if (mysytem("./cake "
" -D__x86_64__ "
" -analyze "
" -I/usr/lib/gcc/x86_64-linux-gnu/11/include/ "
" -I/usr/local/include/ "
" -I/usr/include/x86_64-linux-gnu/ "
" -I/usr/include/ "
" -I/usr/include/ "
HEADER_FILES
SOURCE_FILES) != 0)
{
Expand All @@ -311,7 +325,7 @@ int main()
#endif

#ifdef TEST
int test_result = system(RUN OUTPUT);
int test_result = mysytem(RUN OUTPUT);
if (test_result)
{
printf("\n");
Expand Down
44 changes: 24 additions & 20 deletions src/build.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,24 +106,28 @@
#endif



#define ESC "\x1b"
#define CSI "\x1b["
#define RESET ESC "[0m"
#define BLACK "\x1b[30m"
#define BLUE "\x1b[34m"
#define GREEN "\x1b[32m"
#define CYAN "\x1b[36m"
#define RED "\x1b[31;1m"
#define MAGENTA "\x1b[35m"
#define BROWN "\x1b[31m"
#define LIGHTGRAY "\x1b[30;1m"
#define DARKGRAY "\x1b[30m"
#define LIGHTBLUE "\x1b[34;1m"
#define LIGHTGREEN "\x1b[32,1m"
#define LIGHTCYAN "\x1b[36;1m"
#define LIGHTRED "\x1b[31;1m"
#define LIGHTMAGENTA "\x1b[35;1m"
#define YELLOW "\x1b[33;1m"
#define WHITE "\x1b[37;1m"
#ifdef WITH_ANSI_COLOR
#define COLOR_ESC(x) x
#else
#define COLOR_ESC(x) ""
#endif
#define ESC COLOR_ESC("\x1b")
#define CSI COLOR_ESC("\x1b[")
#define RESET ESC COLOR_ESC("[0m")
#define BLACK COLOR_ESC("\x1b[30m")
#define BLUE COLOR_ESC("\x1b[34m")
#define GREEN COLOR_ESC("\x1b[32m")
#define CYAN COLOR_ESC("\x1b[36m")
#define RED COLOR_ESC("\x1b[31;1m")
#define MAGENTA COLOR_ESC("\x1b[35m")
#define BROWN COLOR_ESC("\x1b[31m")
#define LIGHTGRAY COLOR_ESC("\x1b[30;1m")
#define DARKGRAY COLOR_ESC("\x1b[30m")
#define LIGHTBLUE COLOR_ESC("\x1b[34;1m")
#define LIGHTGREEN COLOR_ESC("\x1b[32,1m")
#define LIGHTCYAN COLOR_ESC("\x1b[36;1m")
#define LIGHTRED COLOR_ESC("\x1b[31;1m")
#define LIGHTMAGENTA COLOR_ESC("\x1b[35;1m")
#define YELLOW COLOR_ESC("\x1b[33;1m")
#define WHITE COLOR_ESC("\x1b[37;1m")

9 changes: 5 additions & 4 deletions src/console.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

#ifdef _WIN32
#include <Windows.h>
#else
Expand All @@ -22,7 +21,8 @@ bool enable_vt_mode(void)

int c_kbhit(void)
{
struct termios oldt, newt;
struct termios oldt = {0};
struct termios newt = {0};
int ch;
int oldf;

Expand Down Expand Up @@ -50,7 +50,8 @@ int c_kbhit(void)
/* Read 1 character without echo */
int c_getch(void)
{
struct termios old, new;
struct termios old = {0};
struct termios new = {0};
int ch;

tcgetattr(0, &old);
Expand All @@ -72,7 +73,7 @@ int c_getch(void)
bool enable_vt_mode(void)
{
//missing in mingw (installed with codeblocs)
#ifndef ENABLE_VIRTUAL_TERMINAL_PROCESSING
#ifndef ENABLE_VIRTUAL_TERMINAL_PROCESSING
#define ENABLE_VIRTUAL_TERMINAL_PROCESSING 0x0004
#endif

Expand Down
Loading