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

failed to build in gentoo #1907

Open
rpolasek opened this issue Jan 29, 2025 · 7 comments
Open

failed to build in gentoo #1907

rpolasek opened this issue Jan 29, 2025 · 7 comments
Assignees
Labels
Build issue Issue building c3c Fixed Needs Verification Fixed, but needs verification that it works
Milestone

Comments

@rpolasek
Copy link

rpolasek commented Jan 29, 2025

hi, trying to build the latest version from git in gentoo...

FAILED: CMakeFiles/c3c.dir/src/compiler/sema_stmts.c.o /usr/bin/x86_64-pc-linux-gnu-gcc -DCURL_FOUND=1 -DLLVM_AVAILABLE=1 -DTB_AVAILABLE=0 -I/usr/lib/llvm/19/include -I/var/tmpfs/portage/dev-lang/c3-9999/work/c3-9999/src -I/var/tmpfs/portage/dev-lang/c3-9999/work/c3-9999_build -I/var/tmpfs/portage/dev-lang/c3-9999/work/c3-9999/wrapper/include -I/var/tmpfs/portage/dev-lang/c3-9999/work/c3-9999/dependencies/miniz -march=native -O2 -pipe -std=gnu11 -D_GNU_SOURCE -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -pthread -Wall -Werror -Wno-unknown-pragmas -Wno-unused-result -Wno-unused-function -Wno-unused-variable -Wno-unused-parameter -MD -MT CMakeFiles/c3c.dir/src/compiler/sema_stmts.c.o -MF CMakeFiles/c3c.dir/src/compiler/sema_stmts.c.o.d -o CMakeFiles/c3c.dir/src/compiler/sema_stmts.c.o -c /var/tmpfs/portage/dev-lang/c3-9999/work/c3-9999/src/compiler/sema_stmts.c In function ‘sema_analyse_ct_foreach_stmt’, inlined from ‘sema_analyse_statement_inner’ at /var/tmpfs/portage/dev-lang/c3-9999/work/c3-9999/src/compiler/sema_stmts.c:3139:11: /var/tmpfs/portage/dev-lang/c3-9999/work/c3-9999/src/compiler/sema_stmts.c:2805:32: error: ‘count’ may be used uninitialized [-Werror=maybe-uninitialized] 2805 | for (unsigned i = 0; i < count; i++) | ~~^~~~~~~ /var/tmpfs/portage/dev-lang/c3-9999/work/c3-9999/src/compiler/sema_stmts.c: In function ‘sema_analyse_statement_inner’: /var/tmpfs/portage/dev-lang/c3-9999/work/c3-9999/src/compiler/sema_stmts.c:2727:18: note: ‘count’ was declared here 2727 | unsigned count; | ^~~~~ cc1: all warnings being treated as errors

@lerno lerno self-assigned this Jan 30, 2025
@lerno lerno added the Build issue Issue building c3c label Jan 30, 2025
@lerno
Copy link
Collaborator

lerno commented Jan 30, 2025

That looks like incorrect diagnostics because it fails to properly analyse the flow. But I changed it so hopefully it now compiles for you.

@lerno lerno added the Fixed Needs Verification Fixed, but needs verification that it works label Jan 30, 2025
@lerno lerno added this to the 0.6.7 milestone Jan 30, 2025
@rpolasek
Copy link
Author

rpolasek commented Jan 30, 2025

@lerno, thank you for the prompt fix. unfortunately, there is next problem with compilation but i can feel we're close and close to the final success build in gentoo. (btw. i can provide you c3-9999.ebuild for gentoo at the end).

here is a piece of log message with an error but i'm enclosing a full build log for better investigaton...

FAILED: CMakeFiles/c3c.dir/src/utils/file_utils.c.o /usr/bin/x86_64-pc-linux-gnu-gcc -DCURL_FOUND=1 -DLLVM_AVAILABLE=1 -DTB_AVAILABLE=0 -I/usr/lib/llvm/19/include -I/var/tmpfs/portage/dev-lang/c3-9999/work/c3-9999/src -I/var/tmpfs/portage/dev-lang/c3-9999/work/c3-9999_build -I/var/tmpfs/portage/dev-lang/c3-9999/work/c3-9999/wrapper/include -I/var/tmpfs/portage/dev-lang/c3-9999/work/c3-9999/dependencies/miniz -march=native -O2 -pipe -std=gnu11 -D_GNU_SOURCE -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -pthread -Wall -Werror -Wno-unknown-pragmas -Wno-unused-result -Wno-unused-function -Wno-unused-variable -Wno-unused-parameter -MD -MT CMakeFiles/c3c.dir/src/utils/file_utils.c.o -MF CMakeFiles/c3c.dir/src/utils/file_utils.c.o.d -o CMakeFiles/c3c.dir/src/utils/file_utils.c.o -c /var/tmpfs/portage/dev-lang/c3-9999/work/c3-9999/src/utils/file_utils.c /var/tmpfs/portage/dev-lang/c3-9999/work/c3-9999/src/utils/file_utils.c: In function ‘file_append_path_temp’: /var/tmpfs/portage/dev-lang/c3-9999/work/c3-9999/src/utils/file_utils.c:509:53: error: ‘%s’ directive output may be truncated writing up to 16382 bytes into a region of size between 1 and 16382 [-Werror=format-truncation=] 509 | snprintf(path_buffer, PATH_BUFFER_SIZE, "%s/%s", path, name); | ^~ In file included from /usr/include/stdio.h:970, from /var/tmpfs/portage/dev-lang/c3-9999/work/c3-9999/src/utils/common.h:9, from /var/tmpfs/portage/dev-lang/c3-9999/work/c3-9999/src/utils/file_utils.c:7: In function ‘snprintf’, inlined from ‘file_append_path_temp’ at /var/tmpfs/portage/dev-lang/c3-9999/work/c3-9999/src/utils/file_utils.c:509:2: /usr/include/bits/stdio2.h:68:10: note: ‘__builtin___snprintf_chk’ output between 3 and 32766 bytes into a destination of size 16384 68 | return __builtin___snprintf_chk (__s, __n, __USE_FORTIFY_LEVEL - 1, | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 69 | __glibc_objsize (__s), __fmt, | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 70 | __va_arg_pack ()); | ~~~~~~~~~~~~~~~~~ /var/tmpfs/portage/dev-lang/c3-9999/work/c3-9999/src/utils/file_utils.c: In function ‘file_append_path_temp’: /var/tmpfs/portage/dev-lang/c3-9999/work/c3-9999/src/utils/file_utils.c:514:52: error: ‘%s’ directive output may be truncated writing up to 16381 bytes into a region of size between 2 and 16383 [-Werror=format-truncation=] 514 | snprintf(path_buffer, PATH_BUFFER_SIZE, "%s%s", path, name); | ^~ In function ‘snprintf’, inlined from ‘file_append_path_temp’ at /var/tmpfs/portage/dev-lang/c3-9999/work/c3-9999/src/utils/file_utils.c:514:2: /usr/include/bits/stdio2.h:68:10: note: ‘__builtin___snprintf_chk’ output between 2 and 32764 bytes into a destination of size 16384 68 | return __builtin___snprintf_chk (__s, __n, __USE_FORTIFY_LEVEL - 1, | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 69 | __glibc_objsize (__s), __fmt, | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 70 | __va_arg_pack ()); | ~~~~~~~~~~~~~~~~~ cc1: all warnings being treated as errors

@rpolasek
Copy link
Author

rpolasek commented Jan 30, 2025

i've just investigated the code and you don't handle a buffer overflow well at line 500 in the file file_utils.c. the check should be path_len + name_len + 2 >= PATH_BUFFER_SIZE (extra 1 for the / or \, and 1 for \0). also path_buffer[name_len + path_len + 1] = 0; is redundant since snprintf ensures a null-terminated string. long story short - i've rewritten whole function file_append_path_temp and now i'm able to compile it in gentoo.

const char *file_append_path_temp(const char *path, const char *name) {
    size_t path_len = strlen(path);
    if (path_len == 0) return name; // if no path, return name directly

    size_t name_len = strlen(name);

    // ensure there's space for path, separator, name, and null terminator
    if (path_len + name_len + 2 > PATH_BUFFER_SIZE) {
        error_exit("Error generating path from %s and %s: buffer max size exceeded.", path, name);
        return NULL;
    }

    // determine if we need a separator
    char separator = '/';
#if defined(_WIN32)
    separator = '\\';
#endif

    // format the string safely
    int written;
    if (path[path_len - 1] == '/' || path[path_len - 1] == '\\') {
        written = snprintf(path_buffer, PATH_BUFFER_SIZE, "%s%s", path, name);
    } else {
        written = snprintf(path_buffer, PATH_BUFFER_SIZE, "%s%c%s", path, separator, name);
    }

    // check if truncation occurred
    if (written < 0 || (size_t)written >= PATH_BUFFER_SIZE) {
        error_exit("Error generating path from %s and %s: snprintf truncation occurred.", path, name);
        return NULL;
    }

    return path_buffer;
}

@rpolasek
Copy link
Author

rpolasek commented Jan 30, 2025

as soon as the code above is fixed you can provide all gentoo users c3-9999.ebuild and c3-0.6.6.ebuild.

@lerno
Copy link
Collaborator

lerno commented Jan 30, 2025

I modified it slightly, hopefully it still passes.

@rpolasek
Copy link
Author

rpolasek commented Jan 30, 2025

i've updated the links for my ebuilds above and i can confirm it works great in gentoo now. however, i have to ask you if your changed code below is really ok primarily for non windows platform (separator = '/'):

bool insert_separator = path[path_len - 1] == '/' || path[path_len - 1] == separator;

@lerno
Copy link
Collaborator

lerno commented Jan 31, 2025

Yes, should be fine since both comparisons are the same.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Build issue Issue building c3c Fixed Needs Verification Fixed, but needs verification that it works
Projects
None yet
Development

No branches or pull requests

2 participants