[m-dev.] diff: fix copy/2 string literal alignment bug

Warwick Harvey wharvey at cs.monash.edu.au
Thu Mar 25 15:34:12 AEDT 1999


Fergus wrote:
> Estimated hours taken: 2
> 
> Fix a bug where copy/2 was returning bogus data when copying string literals.
> 
> runtime/mercury_deep_copy_body.h:
> 	Change the code so that it doesn't assume that string literals
> 	must be aligned, since currently they aren't.

This fix was not quite complete:

> Index: runtime/mercury_deep_copy_body.h
> ===================================================================
> RCS file: /home/mercury1/repository/mercury/runtime/mercury_deep_copy_body.h,v
> retrieving revision 1.5
> diff -u -r1.5 mercury_deep_copy_body.h
> --- mercury_deep_copy_body.h	1999/03/02 09:46:10	1.5
> +++ mercury_deep_copy_body.h	1999/03/24 03:07:49
> @@ -169,7 +169,7 @@
>                  incr_saved_hp_atomic(new_data, 
>                      (strlen((String) data_value) + sizeof(Word)) 
                                        ^^^^^^^^^^ this should be "data"
>                                  / sizeof(Word));
> -                strcpy((String) new_data, (String) data_value);
> +                strcpy((String) new_data, (String) data);
>                  leave_forwarding_pointer(data_ptr, new_data);
>              } else {
>                  new_data = data;

With this change, Tom's RoboRally program is much more stable (the previous 
change actually made it crash earlier), and most of the remaining bugs look 
like they could be in that program rather than Mercury.

Of course, Greg's program still crashes.  :-(  But that could be any number 
of things...

Warwick




More information about the developers mailing list