Sercon Terminal Finally Works!

After days of individual and collaborated experiments with my buddy Wassim, I finally came up with a solution to fix the sercon buffer parser issue.

Basically, when I typed a command, the command buffer would be corrupted. Like this:

[/root | 1412814792 UDT (Epoch)]
Sercon$ help
Error: ”  mkfs.fatS*    “ is not a registered command of the SerCon Terminal”

As shown in bold, the buffer is displaying random binaries that were in the RAM.

int getCommend (char buf [], int n) is a function used to obtain the first n keypresses that the user makes. A return key automatically makes the function return. The integer returned is the # of characters actually typed before a return key or a buffer overflow.

char buf [100]; // declare buffer
memset (buf, 0, sizeof(buf)); // force initialize buffer
getCommand (buf, 100);

No problems were detected in any of those lines of code.

Then, I called the int execSerCon (char command []) function.

execSerCon runs a registered command of the terminal (via its char array argument).

There, I went

for (int i=0; i<sizeof(command); ++i) {
if (command [i] != 0)
err = 0;
}

if (err)
return -1;

for (int i=0; i<sizeof(Commands)/sizeof(serconcommand_t); ++i) {
if (strcmp (Commands [i].name, command) == 0) { // find match

int commandexit = Commands [i].fnptr (currentcommand_argv, currentcommand_argc); // execute command
if (commandexit == -1)
kprintf (“\nCommand Exited with Error Code -1”);
if (commandexit == 0)
kprintf (“\nCommand Successfully Executed”);
else
kprintf (“\nCommand Exited with Unrecognized Return Code %d”, commandexit);

return 0;
}
}
kprintf (KRED “\nError: %s is not a command, executable file, or a script” KRST, str);

The problem was that I was directly casting a char [] into a char*. Such feature was supported in Microsoft VC++ CL Compiler, but GCC seems not to like it.

Therefore, to fix the error, I had to create a new char* string that has the same contents as the char[]. Simple.

char* str;
str = kmalloc (sizeof(command);

for (int i=0; i<sizeof(command); ++i)
str[i] = command[i];

Bug Fixed!

Arcrascent OS Sercon [Master] Finally Working
Arcrascent OS Sercon [Master] Finally Working

Leave a comment