Skip to content
Open
Changes from all commits
Commits
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
33 changes: 33 additions & 0 deletions source/test/testing_purpose.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#include <stdio.h>
Copy link

Copilot AI Mar 4, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR description says "Please do not merge". To avoid accidental merges, consider marking this PR as a Draft or closing it until it’s ready to land.

Copilot uses AI. Check for mistakes.
#include <string.h>
Comment on lines +1 to +2
Copy link

Copilot AI Mar 4, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This new C file is missing the standard Apache 2.0 license/header block that appears at the top of other source/test files in this repo. Please add the project’s usual header to keep licensing consistent.

Copilot uses AI. Check for mistakes.

void reverseString(char *str) {
int start = 0;
int end = strlen(str) - 1;
Comment on lines +5 to +6
Copy link

Copilot AI Mar 4, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

int end = strlen(str) - 1; can underflow when the input string is empty (strlen==0) and also truncates size_t into int, which is implementation-defined for long strings. Consider using size_t len = strlen(str); and returning early when len < 2, then index with size_t/ptrdiff_t safely.

Suggested change
int start = 0;
int end = strlen(str) - 1;
if (str == NULL) {
return;
}
size_t len = strlen(str);
if (len < 2) {
return;
}
size_t start = 0;
size_t end = len - 1;

Copilot uses AI. Check for mistakes.
char temp;

while (start < end) {
temp = str[start];
str[start] = str[end];
str[end] = temp;
start++;
end--;
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please add a print here

}

int main() {
char str[100];

printf("Enter a string: ");
fgets(str, sizeof(str), stdin);

// Remove newline if present
str[strcspn(str, "\n")] = 0;

Comment on lines +21 to +26
Copy link

Copilot AI Mar 4, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The return value of fgets isn’t checked. If stdin is closed/EOF, fgets returns NULL and str remains uninitialized, leading to undefined behavior in strcspn and reverseString. Please handle the NULL case (e.g., print an error and exit).

Copilot uses AI. Check for mistakes.
reverseString(str);
printf("Reversed string: %s\n", str);

return 0;
}


Comment on lines +18 to +33
Copy link

Copilot AI Mar 4, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This adds an interactive main() program under source/test/, but the test suite here is built as a single gtest binary (see source/test/Makefile.am and gtest_main.cpp). If this file is only for workflow experimentation, it should be removed before merging; if it’s meant to test string reversal, consider converting it into a gtest unit test instead of prompting on stdin.

Suggested change
int main() {
char str[100];
printf("Enter a string: ");
fgets(str, sizeof(str), stdin);
// Remove newline if present
str[strcspn(str, "\n")] = 0;
reverseString(str);
printf("Reversed string: %s\n", str);
return 0;
}

Copilot uses AI. Check for mistakes.