mirror of
https://gitlab.os-k.eu/os-k-team/os-k.git
synced 2023-08-25 14:03:10 +02:00
argv bug fix
This commit is contained in:
parent
58b896ea2a
commit
890cc6e615
@ -83,7 +83,7 @@ error_t KalCmdLineToArgVecEx(const char *cmdLine,
|
|||||||
assert(argv && cmdLine);
|
assert(argv && cmdLine);
|
||||||
|
|
||||||
// Another ARG_MAX-wide buffer
|
// Another ARG_MAX-wide buffer
|
||||||
char *buffer = *argv + ARG_MAX;
|
char *buffer = bufptr + ARG_MAX;
|
||||||
|
|
||||||
argv[0] = buffer;
|
argv[0] = buffer;
|
||||||
|
|
||||||
|
@ -27,7 +27,7 @@
|
|||||||
int shcol = VGA_COLOR_LIGHT_GREY;
|
int shcol = VGA_COLOR_LIGHT_GREY;
|
||||||
|
|
||||||
int shargc = 0;
|
int shargc = 0;
|
||||||
char *argv0 = 0;
|
char *argvbuf = 0;
|
||||||
char **shargv = 0;
|
char **shargv = 0;
|
||||||
|
|
||||||
void ExecuteCommand(char *cmdbuf)
|
void ExecuteCommand(char *cmdbuf)
|
||||||
@ -40,7 +40,7 @@ void ExecuteCommand(char *cmdbuf)
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
memzero(*shargv, ARG_MAX);
|
memzero(*shargv, ARG_MAX);
|
||||||
rc = KalCmdLineToArgVec(cmdbuf, &shargc, argv0);
|
rc = KalCmdLineToArgVec(cmdbuf, &shargc, argvbuf);
|
||||||
if (rc) KeStartPanic("Shell: Couldn't parse command line: %d", rc);
|
if (rc) KeStartPanic("Shell: Couldn't parse command line: %d", rc);
|
||||||
|
|
||||||
for (cmd = cmdtable; cmd->name != NULL; cmd++) {
|
for (cmd = cmdtable; cmd->name != NULL; cmd++) {
|
||||||
@ -51,8 +51,10 @@ void ExecuteCommand(char *cmdbuf)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
assert(shargv[0] == argvbuf + ARG_MAX);
|
||||||
|
|
||||||
if (found == false) {
|
if (found == false) {
|
||||||
KernLog("err: command not found: '%s' (%ld)\n",
|
KernLog("err: command not found: '%.255s' (%ld)\n",
|
||||||
shargv[0], strlen(shargv[0]));
|
shargv[0], strlen(shargv[0]));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -65,9 +67,9 @@ void KeStartShell(void)
|
|||||||
char *cmdbuf = malloc(CMDBUFSIZE);
|
char *cmdbuf = malloc(CMDBUFSIZE);
|
||||||
char *bufptr = cmdbuf;
|
char *bufptr = cmdbuf;
|
||||||
|
|
||||||
argv0 = malloc(ARG_MAX * 2);
|
argvbuf = malloc(ARG_MAX * 2);
|
||||||
memzero(argv0, ARG_MAX * 2);
|
memzero(argvbuf, ARG_MAX * 2);
|
||||||
shargv = (char **)argv0;
|
shargv = (char **)argvbuf;
|
||||||
|
|
||||||
KernLog("\n%Cshell> ", shcol);
|
KernLog("\n%Cshell> ", shcol);
|
||||||
BFlushBuf(BStdOut);
|
BFlushBuf(BStdOut);
|
||||||
|
@ -110,7 +110,7 @@ error_t vbprintf(Buffer_t *buf, const char *fmt, va_list ap)
|
|||||||
{
|
{
|
||||||
error_t rc = 0;
|
error_t rc = 0;
|
||||||
|
|
||||||
int width, prec, len;
|
ssize_t width, prec, len;
|
||||||
char type;
|
char type;
|
||||||
|
|
||||||
uchar uch;
|
uchar uch;
|
||||||
@ -199,7 +199,7 @@ error_t vbprintf(Buffer_t *buf, const char *fmt, va_list ap)
|
|||||||
fmt++; \
|
fmt++; \
|
||||||
name = va_arg(ap, int); \
|
name = va_arg(ap, int); \
|
||||||
} else { \
|
} else { \
|
||||||
while (isdigit(*fmt) && name < CONVBUFSIZE) { \
|
while (isdigit(*fmt)) { \
|
||||||
name = 10 * name + (*fmt - '0'); \
|
name = 10 * name + (*fmt - '0'); \
|
||||||
fmt++; \
|
fmt++; \
|
||||||
} \
|
} \
|
||||||
@ -221,12 +221,6 @@ error_t vbprintf(Buffer_t *buf, const char *fmt, va_list ap)
|
|||||||
bextractwp(prec);
|
bextractwp(prec);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Make sure they're not too big
|
|
||||||
if (width > CONVBUFSIZE || prec > CONVBUFSIZE) {
|
|
||||||
rc = EINVAL;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
//
|
||||||
// Length field
|
// Length field
|
||||||
//
|
//
|
||||||
@ -270,12 +264,14 @@ error_t vbprintf(Buffer_t *buf, const char *fmt, va_list ap)
|
|||||||
if (!(base < 0 || base > VGA_COLOR_WHITE))
|
if (!(base < 0 || base > VGA_COLOR_WHITE))
|
||||||
rc = bputc(buf, RtlColorToChar(base));
|
rc = bputc(buf, RtlColorToChar(base));
|
||||||
|
|
||||||
|
|
||||||
|
assert(!rc && 1);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Strings
|
// Strings
|
||||||
else if (type == 's') {
|
if (type == 's') {
|
||||||
s = va_arg(ap, char *);
|
s = va_arg(ap, char *);
|
||||||
|
|
||||||
if (s == NULL) s = "(null)";
|
if (s == NULL) s = "(null)";
|
||||||
@ -292,8 +288,16 @@ error_t vbprintf(Buffer_t *buf, const char *fmt, va_list ap)
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Make sure width and prec aren't too big
|
||||||
|
// (We didn't do that earlier because %s uses width)
|
||||||
|
if (width > CONVBUFSIZE || prec > CONVBUFSIZE) {
|
||||||
|
rc = EINVAL;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
// Decimal, unsigned decimal, hexadecimal, octal and binary numbers
|
// Decimal, unsigned decimal, hexadecimal, octal and binary numbers
|
||||||
else if (type == 'd' || type == 'i') { base = 10; sgn = 1; }
|
if (type == 'd' || type == 'i') { base = 10; sgn = 1; }
|
||||||
else if (type == 'X') { base = 16; cap = 1; }
|
else if (type == 'X') { base = 16; cap = 1; }
|
||||||
else if (type == 'x') { base = 16; }
|
else if (type == 'x') { base = 16; }
|
||||||
else if (type == 'u') { base = 10; }
|
else if (type == 'u') { base = 10; }
|
||||||
@ -406,7 +410,8 @@ error_t vbprintf(Buffer_t *buf, const char *fmt, va_list ap)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// For debugging purposes
|
// For debugging purposes
|
||||||
assert(!rc);
|
if(rc)KeStartPanic("%s",strerror(rc));
|
||||||
|
assert(!rc && "vbprintf() error");
|
||||||
|
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user