pike.git
/
src
/
operators.c
version
»
Context lines:
10
20
40
80
file
none
3
pike.git/src/operators.c:1:
/* || This file is part of Pike. For copyright information see COPYRIGHT. || Pike is distributed under GPL, LGPL and MPL. See the file COPYING || for more information.
-
|| $Id: operators.c,v 1.
165
2002
/
11
/
26
16
:
55
:
55
grubba
Exp $
+
|| $Id: operators.c,v 1.
166
2003
/
05
/
15
15
:
10
:
14
mast
Exp $
*/ #include "global.h" #include <math.h>
-
RCSID("$Id: operators.c,v 1.
165
2002
/
11
/
26
16
:
55
:
55
grubba
Exp $");
+
RCSID("$Id: operators.c,v 1.
166
2003
/
05
/
15
15
:
10
:
14
mast
Exp $");
#include "interpret.h" #include "svalue.h" #include "multiset.h" #include "mapping.h" #include "array.h" #include "stralloc.h" #include "opcodes.h" #include "operators.h" #include "language.h" #include "pike_memory.h"
pike.git/src/operators.c:3489:
#define THIS ((struct string_assignment_storage *)(CURRENT_STORAGE)) /*! @decl int `[](int i, int j) *! *! String index operator. */ static void f_string_assignment_index(INT32 args) { INT_TYPE i; get_all_args("string[]",args,"%i",&i); if(i<0) i+=THIS->s->len;
-
if(i<0)
-
i+=THIS->s->len;
+
if(i<0 || i>=THIS->s->len) Pike_error("Index %"PRINTPIKEINT"d is out of range 0 - %ld.\n", i, PTRDIFF_T_TO_LONG(THIS->s->len - 1)); else i=index_shared_string(THIS->s,i); pop_n_elems(args); push_int(i); } /*! @decl int `[]=(int i, int j) *! *! String assign index operator. */ static void f_string_assignment_assign_index(INT32 args) { INT_TYPE i,j; union anything *u; get_all_args("string[]=",args,"%i%i",&i,&j); if((u=get_pointer_if_this_type(THIS->lval, T_STRING))) {
-
free_string(THIS->s);
+
if(i<0) i+=u->string->len; if(i<0 || i>=u->string->len) Pike_error("String index out of range %ld\n",(long)i);
-
+
free_string(THIS->s);
u->string=modify_shared_string(u->string,i,j); copy_shared_string(THIS->s, u->string); }else{ lvalue_to_svalue_no_free(sp,THIS->lval); sp++; if(sp[-1].type != T_STRING) Pike_error("string[]= failed.\n"); if(i<0) i+=sp[-1].u.string->len; if(i<0 || i>=sp[-1].u.string->len) Pike_error("String index out of range %ld\n",(long)i); sp[-1].u.string=modify_shared_string(sp[-1].u.string,i,j);