Software Transformation Problems

byrum@sleet.cs.odu.edu
21 Jun 88 18:12:23 GMT

          From comp.compilers

Related articles
Software Transformation Problems byrum@sleet.cs.odu.edu (1988-06-21)
| List of all articles for this month |

From: byrum@sleet.cs.odu.edu
Newsgroups: comp.compilers,comp.software-eng,comp.lang.ada,comp.lang.c,comp.lang.fortran,comp.lang.modula2,comp.lang.pascal,comp.lang.misc
Date: 21 Jun 88 18:12:23 GMT
Organization: Old Dominion University, Norfolk, Va.

I am conducting some research in software transformation. One problem area
involves source-to-source changes in which the new piece of code does not
perform as the original. The source-to-source modifications are assumed to be
"semantically correct." These may be errors induced either by mistakes in the
original code or by the programmer's taking advantage of the compiler's
characteristics. Could all you people in net land send me some of your horror
stories and/or problems encountered during development and/or maintenance?
Examples in any language are welcome.


I thought of some interesting problems with source-to-source transformations
on C code. Below is the example.


The problem is due to several library functions that work with
strings.


Consider:


>> #include <stdio.h>
>>
>> #define LONGSTRING "1234567890123"
>>
>> main()
>> {
>> extern char *strcpy();
>>
>> char string[10], a, b, c;
>>
>> strcpy( string, LONGSTRING);
>> printf( "the string is {%s}\n", string);
>> a = 'A';
>> b = 'B';
>> c = 'C';
>> printf( "a = {%c} b = {%c} c = {%c}\n", a, b, c);
>> }


Notice that the programmer takes advantage of string and the variable space
behind it. LONGSTRING consist of 13 characters and string has only 10
allocated spaces in the array.


OUTPUT:
>> the string is {1234567890123}
>> a = {A} b = {B} c = {C}


Now consider:


>> #include <stdio.h>
>>
>> #define LONGSTRING "1234567890123"
>>
>> main()
>> {
>> extern char *strcpy();
>>
>> char string[10], a = 'A', b = 'B', c = 'C';
>>
>> strcpy( string, LONGSTRING);
>> printf( "the string is {%s}\n", string);
>> printf( "a = {%c} b = {%c} c = {%c}\n", a, b, c);
>> }


Notice, that the assignments of a, b, and c have been moved to the declaration.
Since a, b, and c have no other dependencies in the program, this is a legal
source-to-source transformation.


OUTPUT
>> the string is {1234567890123}
>> a = {1} b = {2} c = {3}


I have found that through carelessness this type of problem may occur
often. (I realize that the programmer should be responsible for checking the
array bounds!) This is just an example of a piece of code that works before
transformation and not after.


If people are interested I will compile the best examples and
repost them. Any help is appreciated.


Direct flames to /dev/null. Respond by email, not posting. If I
get enough responses, I will summarize.




                                                                | Terry Franklin (Frank) Byrum
                                                                | Old Universion University
      ___ | INET: byrum@cs.odu.edu
    /__ _. __. _ _ /_ | UUCP: ...!uunet!xanth!brooks!byrum
  / _/ \_(_/|_|\|_/ \ | DISCLAIMER: No one listens anyway!
--


Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.