File: sharing4.c

package info (click to toggle)
lclint 1%3A2.4b-1
  • links: PTS
  • area: main
  • in suites: potato
  • size: 7,996 kB
  • ctags: 9,589
  • sloc: ansic: 100,034; lex: 2,754; yacc: 2,472; makefile: 835
file content (47 lines) | stat: -rw-r--r-- 1,735 bytes parent folder | download | duplicates (10)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
/*@only@*/   char *globonly1;
/*@only@*/   char *globonly2;
/*@only@*/   char *globonly3;
/*@only@*/   char *globonly4;
/*@only@*/   char *globonly5;
/*@shared@*/ char *globshared1;
/*@shared@*/ char *globshared2;

extern void free (/*@out@*/ /*@only@*/ void *s);
extern /*@only@*/ char *string_copy (char *s) /*@modifies nothing;@*/ ;

int f(/*@only@*/ char *only1, /*@only@*/ char *only2, /*@only@*/ char *only3, 
      char *temp1, /*@temp@*/ char *temp2, 
      /*@shared@*/ char *shared1, /*@shared@*/ char *shared2)
{
  char *local1;

  globonly1 = only1;   /* 1. Only storage globonly1 not released before assignment */
  free (globonly2);  
  globonly2 = only2; 
  free (globonly3);     /* okay...for now */

  globonly4 = shared1; /* 2. Only storage globonly4 not released before assignment
			  3. Shared storage assigned to only */
  globshared1 = shared2;         
  globshared1 = globshared2;
  globshared1 = globonly5; /* 4. Only storage assigned to shared */

  local1 = globonly1;   
  globshared1 = local1; /* 5. Only storage globonly1 assigned to shared (local1 aliases */
                        /* 6. Kept storage only1 assigned to shared (local1 aliases */
  globshared1 = string_copy (local1); /* 7. Only storage assigned to shared */
  
  globshared2 = temp2; /* 8. Temp storage temp2 assigned to shared */
  globonly4 = temp1;   /* 9. Only storage globonly4 not released before assignment
			 10. Temp storage temp1 assigned to only: globonly4 = temp1 */

  free (shared1); /* 11. Shared storage shared1 passed as only param */
  *only3 = 'a';
  *shared2 = 'c';

  return 3; /* 12. Only storage only3 not released before return */
	    /* 13. Function returns with global globonly3 referencing released */
}