[splint-discuss] Dependent storage assigned to unqualified

Vangelis Katsikaros ibob17 at yahoo.gr
Sat Oct 24 07:03:12 PDT 2009


Hello

I have encountered a "Dependent storage assigned to unqualified" warning
but I couldn't find sufficient information to understand what this is about.

$ splint -exportlocal dep.c
Splint 3.1.2 --- 11 May 2008

dep.c: (in function main)
dep.c:41:5: Dependent storage assigned to unqualified:
                FARRAY[i] = fopen(cur_path, "r")
   Dependent storage is transferred to a non-dependent reference. (Use
   -dependenttrans to inhibit warning)

Finished checking --- 1 code warning


I understand that the warning has to do with "5 Memory Management" and
more especially with "5.2.1 Unshared References", but I fail to see the
connection.

Any hints would be valuable :)

Regards
Vangelis Katsikaros

PS. There is only one reference of dependent-trans on the manual which
doesn't provide much information (it can only be found in page 83).

//===========================================================
#include <stdio.h>
#include <stdlib.h>

#define SIZE 4

/*
we want to read several file (here SIZE) that have the same prefix. So we
append an integer [0..9] to the basepath. Then we open the file of the
appended path
*/

int main(){

   int i = 0;
   int read_chars = 0;

   FILE* FARRAY[ SIZE ];

   char basepath[] = "./directory/fileprefix_";
   char* cur_path = NULL;

   for( i = 0; i < SIZE; i++ ){

     // allocate
     cur_path = ( char* ) malloc(
                             ( sizeof( basepath ) + 2 ) * sizeof( char )
     );
     if( cur_path == NULL ){
       exit(0);
     }

     read_chars = snprintf( cur_path,
                       ( sizeof( basepath ) + 1 ),
                        "%s%d", basepath, i
     );
     printf("%s\n", cur_path );
     if( read_chars <= 0 ){
       exit(0);
     }

     FARRAY[ i ] = fopen( cur_path, "r");
     if( FARRAY[ i ] == NULL ){
       exit(0);
     }

     free(cur_path);
   }

   // finish with reading the files
   for( i = 0; i < SIZE; i++ ){
     (void)fclose( FARRAY[ i ] );
   }

   return 0;

}
//===========================================================




More information about the splint-discuss mailing list