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
34 changes: 34 additions & 0 deletions source/test/testing_purpose.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#include <stdio.h>
#include <string.h>

void reverseString(char *str) {
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.

reverseString has external linkage but appears intended for use only within this file. Mark it static to avoid exporting an unnecessary symbol from the test binary (and potential link conflicts if another test adds the same helper name).

Suggested change
void reverseString(char *str) {
static void reverseString(char *str) {

Copilot uses AI. Check for mistakes.
int start = 0;
int end = strlen(str) - 1;
char temp;

while (start < end) {
temp = str[start];
str[start] = str[end];
str[end] = temp;
start++;
end--;
}
printf("string reversed : %s\n",str);
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.

reverseString performs I/O (printf) in addition to reversing the buffer, and main() prints the reversed string again. Consider keeping reverseString focused on mutation only and letting the caller decide whether/how to print, to avoid duplicated output and make the function reusable in unit tests.

Suggested change
printf("string reversed : %s\n",str);

Copilot uses AI. Check for mistakes.
}

int main() {
char str[100];

printf("Enter a string: ");
fgets(str, sizeof(str), stdin);
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.

fgets return value is not checked. If stdin is closed or an error occurs, str contents are undefined and strcspn/reverseString will operate on uninitialized data. Handle a NULL return from fgets (e.g., print an error and return non-zero) before using str.

Suggested change
fgets(str, sizeof(str), stdin);
if (fgets(str, sizeof(str), stdin) == NULL) {
fprintf(stderr, "Error reading input.\n");
return 1;
}

Copilot uses AI. Check for mistakes.

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

reverseString(str);
printf("Reversed string: %s\n", str);

return 0;
}


Comment on lines +19 to +34
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 file adds an interactive standalone main() program under source/test, but it is not referenced by source/test/Makefile.am (the unit test build enumerates sources explicitly). If this is intended as a unit test, convert it into a gtest test and add it to PsmSsp_gtest_bin_SOURCES; otherwise consider removing it or relocating it outside the test tree to avoid dead/accidental test artifacts in the repo.

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.