small bug fix to string.m

Christopher Rodd SPEIRS crs at students.cs.mu.oz.au
Fri May 16 00:13:41 AEST 1997


Fergus, could you please review this ...
	When looking at string__index, the comments stated that:
%	`Char' is the (`Index' + 1)-th character of `String'.
%	Fails if `Index' is out of range (negative, or greater than or
%	equal to the length of `String').
 but the code did not check if index was negative.


	Chris

compiler/string.m:
	Changed string__index(String, Index, Char) so that it checked 
	if Index was negative, and failed if it was.  The documentation
	already stated that string__index would fail if it was passed a 
	negative index.
	
	

Index: string.m
===================================================================
RCS file: /home/mercury1/repository/mercury/library/string.m,v
retrieving revision 1.88
diff -u -r1.88 string.m
--- string.m	1997/02/19 05:33:01	1.88
+++ string.m	1997/05/15 14:05:49
@@ -1590,7 +1590,7 @@
 :- mode string__index(in, in, out) is semidet.
 */
 :- pragma(c_code, string__index(Str::in, Index::in, Ch::out), "
-	if ((Word) Index >= strlen(Str)) {
+	if ((Word) Index >= strlen(Str) || (Word) Index < 0) {
 		SUCCESS_INDICATOR = FALSE;
 	} else {
 		SUCCESS_INDICATOR = TRUE;



More information about the developers mailing list