SCI: Changed signatures of StrLen and StrCpy to allow NULL pointers. This is
needed for a game bug in KQ6CD. svn-id: r40930
This commit is contained in:
parent
da96ab639e
commit
fd191a4920
2 changed files with 12 additions and 3 deletions
|
@ -141,8 +141,8 @@ SciKernelFunction kfunct_mappers[] = {
|
|||
/*47*/ DEFUN("StrEnd", kStrEnd, "r"),
|
||||
/*48*/ DEFUN("StrCat", kStrCat, "rr"),
|
||||
/*49*/ DEFUN("StrCmp", kStrCmp, "rri*"),
|
||||
/*4a*/ DEFUN("StrLen", kStrLen, "r"),
|
||||
/*4b*/ DEFUN("StrCpy", kStrCpy, "rri*"),
|
||||
/*4a*/ DEFUN("StrLen", kStrLen, "Zr"),
|
||||
/*4b*/ DEFUN("StrCpy", kStrCpy, "rZri*"),
|
||||
/*4c*/ DEFUN("Format", kFormat, "r.*"),
|
||||
/*4d*/ DEFUN("GetFarText", kGetFarText, "iir"),
|
||||
/*4e*/ DEFUN("ReadNumber", kReadNumber, "r"),
|
||||
|
@ -923,6 +923,9 @@ static void *_kernel_dereference_pointer(EngineState *s, reg_t pointer, int entr
|
|||
int maxsize;
|
||||
void *retval = s->seg_manager->dereference(pointer, &maxsize);
|
||||
|
||||
if (!retval)
|
||||
return NULL;
|
||||
|
||||
if (pointer.offset & (align - 1)) {
|
||||
warning("Unaligned pointer read: %04x:%04x expected with %d alignment", PRINT_REG(pointer), align);
|
||||
return NULL;
|
||||
|
|
|
@ -296,7 +296,8 @@ reg_t kStrCpy(EngineState *s, int funct_nr, int argc, reg_t *argv) {
|
|||
if (!src) {
|
||||
warning("Attempt to strcpy FROM invalid pointer %04x:%04x",
|
||||
PRINT_REG(argv[1]));
|
||||
return NULL_REG;
|
||||
*dest = 0;
|
||||
return argv[1];
|
||||
}
|
||||
|
||||
if (argc > 2) {
|
||||
|
@ -632,6 +633,11 @@ reg_t kFormat(EngineState *s, int funct_nr, int argc, reg_t *argv) {
|
|||
reg_t kStrLen(EngineState *s, int funct_nr, int argc, reg_t *argv) {
|
||||
char *str = kernel_dereference_char_pointer(s, argv[0], 0);
|
||||
|
||||
if (!str) {
|
||||
warning("StrLen: invalid pointer %04x:%04x", PRINT_REG(argv[0]));
|
||||
return NULL_REG;
|
||||
}
|
||||
|
||||
return make_reg(0, strlen(str));
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue