Skip to content

[WIP] Add error message for missing filename argument with -f/--file flag#41

Merged
transicle merged 2 commits intomainfrom
copilot/add-error-message-for-file-flag
Mar 27, 2026
Merged

[WIP] Add error message for missing filename argument with -f/--file flag#41
transicle merged 2 commits intomainfrom
copilot/add-error-message-for-file-flag

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Mar 27, 2026

  • Add #define MAX_BUNDLE_PATH_SIZE 2048 and extern const char *libs; after includes
  • Add error handling (with fprintf(stderr, ...)) for -f/--file flag missing argument
  • Add error handling for -o/--output flag missing argument
  • Replace magic number 2048 with MAX_BUNDLE_PATH_SIZE
  • Add bounds checking for snprintf calls with bundle paths
Original prompt
Please apply the following diffs and create a pull request.
Once the PR is ready, give it a title based on the messages of the fixes being applied.

[{"message":"When the -f/--file flag is provided without an argument, the program silently continues without setting file_path, leading to a generic error later. Add an error message when required arguments are missing, such as 'Error: -f/--file requires a filename argument'.","fixFiles":[{"filePath":"src/main.c","diff":"diff --git a/src/main.c b/src/main.c\n--- a/src/main.c\n+++ b/src/main.c\n@@ -79,6 +79,12 @@\n \t\t\t\tfile_path = argv[i + 1];\n \t\t\t\ti++;\n \t\t\t}\n+\t\t\telse\n+\t\t\t{\n+\t\t\t\tprintf(\"Error: -f/--file requires a filename argument\\n\");\n+\t\t\t\tprint_usage(argv[0]);\n+\t\t\t\treturn 1;\n+\t\t\t}\n \t\t}\n \t\telse if (strcmp(argv[i], \"-o\") == 0 || strcmp(argv[i], \"--output\") == 0)\n \t\t{\n@@ -87,6 +93,12 @@\n \t\t\t\tout_path = argv[i + 1];\n \t\t\t\ti++;\n \t\t\t}\n+\t\t\telse\n+\t\t\t{\n+\t\t\t\tprintf(\"Error: -o/--output requires a path argument\\n\");\n+\t\t\t\tprint_usage(argv[0]);\n+\t\t\t\treturn 1;\n+\t\t\t}\n \t\t}\n \t\telse if (strcmp(argv[i], \"-r\") == 0 || strcmp(argv[i], \"--rawir\") == 0)\n \t\t{\n"}]},{"message":"When the -o/--output flag is provided without an argument, the program silently continues. Add an error message when required arguments are missing, such as 'Error: -o/--output requires a path argument'.","fixFiles":[{"filePath":"src/main.c","diff":"diff --git a/src/main.c b/src/main.c\n--- a/src/main.c\n+++ b/src/main.c\n@@ -87,6 +87,12 @@\n \t\t\t\tout_path = argv[i + 1];\n \t\t\t\ti++;\n \t\t\t}\n+\t\t\telse\n+\t\t\t{\n+\t\t\t\tfprintf(stderr, \"Error: -o/--output requires a path argument\\n\");\n+\t\t\t\tprint_usage(argv[0]);\n+\t\t\t\treturn 1;\n+\t\t\t}\n \t\t}\n \t\telse if (strcmp(argv[i], \"-r\") == 0 || strcmp(argv[i], \"--rawir\") == 0)\n \t\t{\n"}]},{"message":"The magic number 2048 for buffer size is unexplained and could lead to buffer overflow if paths exceed this limit. Consider defining this as a named constant (e.g., MAX_BUNDLE_PATH_SIZE) or using dynamic allocation with bounds checking.","fixFiles":[{"filePath":"src/main.c","diff":"diff --git a/src/main.c b/src/main.c\n--- a/src/main.c\n+++ b/src/main.c\n@@ -15,6 +15,8 @@\n #include \"backend/linker/linker.h\"\n #include \"embedded_libs.h\"\n \n+#define MAX_BUNDLE_PATH_SIZE 2048\n+\n bool has_valid_extension(const char* filename)\n {\n \tsize_t len = strlen(filename);\n@@ -232,7 +234,7 @@\n \t\t\t\t\tconst char* outp = resolved_out;\n \t\t\t\t\tint lres;\n \t\t\t\t\tconst char* bundle_paths = semantic_get_bundle_paths();\n-\t\t\t\t\tchar combined_bundle_paths[2048];\n+\t\t\t\t\tchar combined_bundle_paths[MAX_BUNDLE_PATH_SIZE];\n \t\t\t\t\tif (bundle_paths && bundle_paths[0] != '\\0')\n \t\t\t\t\t{\n \t\t\t\t\t\tsnprintf(combined_bundle_paths, sizeof(combined_bundle_paths),\n"}]},{"message":"The snprintf call combining hardcoded path with bundle_paths could overflow the 2048-byte buffer if bundle_paths is very long. While snprintf prevents buffer overflow, the resulting string may be truncated without warning. Add bounds checking or increase buffer size with a safety margin.","fixFiles":[{"filePath":"src/main.c","diff":"diff --git a/src/main.c b/src/main.c\n--- a/src/main.c\n+++ b/src/main.c\n@@ -233,29 +233,45 @@\n \t\t\t\t\tint lres;\n \t\t\t\t\tconst char* bundle_paths = semantic_get_bundle_paths();\n \t\t\t\t\tchar combined_bundle_paths[2048];\n+\t\t\t\t\tbool paths_ok = true;\n \t\t\t\t\tif (bundle_paths && bundle_paths[0] != '\\0')\n \t\t\t\t\t{\n-\t\t\t\t\t\tsnprintf(combined_bundle_paths, sizeof(combined_bundle_paths),\n-\t\t\t\t\t\t         \"src/backend/runtime,%s\", bundle_paths);\n+\t\t\t\t\t\tint n = snprintf(combined_bundle_paths, sizeof(combined_bundle_paths),\n+\t\t\t\t\t\t                 \"src/backend/runtime,%s\", bundle_paths);\n+\t\t\t\t\t\tif (n < 0 || (size_t)n >= sizeof(combined_bundle_paths))\n+\t\t\t\t\t\t{\n+\t\t\t\t\t\t\tfprintf(stderr, \"Error: bundle paths string is too long.\\n\");\n+\t\t\t\t\t\t\texit_code = 5;\n+\t\t\t\t\t\t\tpaths_ok = false;\n+\t\t\t\t\t\t}\n \t\t\t\t\t}\n \t\t\t\t\telse\n \t\t\t\t\t{\n-\t\t\t\t\t\tsnprintf(combined_bundle_paths, sizeof(combined_bundle_paths),\n-\t\t\t\t\t\t         \"src/backend/runtime\");\n+\t\t\t\t\t\tint n = snprintf(combined_bundle_paths, sizeof(combined_bundle_paths),\n+\t\t\t\t\t\t                 \"src/backend/runtime\");\n+\t\t\t\t\t\tif (n < 0 || (size_t)n >= sizeof(combined_bundle_paths))\n+\t\t\t\t\t\t{\n+\t\t\t\t\t\t\tfprintf(stderr, \"Error: bundle paths string is too long.\\n\");\n+\t\t\t\t\t\t\texit_code = 5;\n+\t\t\t\t\t\t\tpaths_ok = false;\n+\t\t\t\t\t\t}\n \t\t\t\t\t}\n-\t\t\t\t\tlres = linker_link_and_bundle(\n-\t\t\t\t\t    ll_path, outp, libs ? libs : \"\", combined_bundle_paths);\n-\n-\t\t\t\t\tif (lres == 0)\n+\t\t\t\t\tif (paths_ok)\n \t\t\t\t\t{\n-\t\t\t\t\t\tprintf(\"Linked executable: %s\\n\", outp);\n-\t\t\t\t\t\tremov...

📍 Connect Copilot coding agent with Jira, Azure Boards or Linear to delegate work to Copilot in one click without leaving your project management tool.

@transicle transicle marked this pull request as ready for review March 27, 2026 20:17
…nds checking, and declare extern libs

Agent-Logs-Url: https://github.com/Cappucina/ADAN/sessions/05e69774-ddb0-427a-86ca-ae94f1fd13e5

Co-authored-by: transicle <173532449+transicle@users.noreply.github.com>
@transicle transicle merged commit 5883cac into main Mar 27, 2026
2 of 3 checks passed
@transicle transicle deleted the copilot/add-error-message-for-file-flag branch March 27, 2026 20:18
Copilot AI requested a review from transicle March 27, 2026 20:18
Copilot stopped work on behalf of transicle due to an error March 27, 2026 20:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants