Basic mid now throws an error on out-of-bounds parameters rather than returning
an uninitialised pointer (and crashing). Fixes: #54
This commit is contained in:
parent
9dede01efe
commit
3f049a4c29
9
lang/basic/lib/lib.h
Normal file
9
lang/basic/lib/lib.h
Normal file
|
@ -0,0 +1,9 @@
|
|||
#ifndef LIB_H
|
||||
#define LIB_H
|
||||
|
||||
extern void error(int index);
|
||||
extern char* salloc(unsigned length);
|
||||
extern void sfree(char* c);
|
||||
|
||||
#endif
|
||||
|
|
@ -1,6 +1,7 @@
|
|||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include "bc_string.h"
|
||||
#include "lib.h"
|
||||
|
||||
/* $Id$ */
|
||||
|
||||
|
@ -11,8 +12,6 @@
|
|||
if (X == 0) \
|
||||
return (0);
|
||||
|
||||
extern char* salloc();
|
||||
|
||||
int _length(String* str)
|
||||
{
|
||||
okr(str);
|
||||
|
@ -158,7 +157,7 @@ String* _mid(int i1, int i2, String* s)
|
|||
|
||||
/* printf("mid fcn called %d %d %s\n",i1,i2,s->strval);*/
|
||||
if (i2 < 0 || i1 < -1)
|
||||
return (s2); /* or error? */
|
||||
error(3);
|
||||
if (i1 == -1)
|
||||
i1 = s->strlength;
|
||||
s2 = _newstr(s->strval);
|
||||
|
|
Loading…
Reference in a new issue