B
Bas Wassink
Hello there,
I'm having trouble understanding a warning produced by 'splint', a
code-checker. The warning produced is:
keywords.c: (in function keyw_get_string)
keywords.c:60:31: Released storage Keywords[].Keyword reachable from global
A global variable does not satisfy its annotations when control
is transferred. (Use -globstate to inhibit warning)
keywords.c:60:11: Storage Keywords[].Keyword released
The line number isn't correct anymore since I snipped some 'irrelevant'
code. Here's the code that causes the warning:
/*
* keywords module for sta65xx, written by Bas Wassink
* started: 2005-09-13
* updated: 2005-09-16
*/
#include <string.h>
#include <stdio.h>
#include "globals.h" /* application wide used constants */
#include "keywords.h" /* prototypes and constants used */
struct keystruct { /* struct used by Keywords table */
char *Keyword;
int Id;
char *Description;
};
/* keywords table */
static struct keystruct Keywords[] = {
{ "byte", KEYW_BYTE, "data as bytes" },
{ "word", KEYW_WORD, "data as words" },
{ "text", KEYW_TEXT, "data as text" }
};
/* return keyword string */
char *keyw_get_string ( int k )
{
int i;
/* check identifier bounds */
if ( ( k >= KEYWORDS_AMOUNT ) || ( k < 0 ) )
return NULL;
/* look up Id in table */
for ( i = 0; i < KEYWORDS_AMOUNT; i++ )
if ( Keywords.Id == k )
return Keywords.Keyword; /* <= This causes the warning */
/* Id not found, return NULL as error code (shouldn't happen) */
return NULL;
}
I know I'm returning a pointer to memory accessible only by this module,
so that's probably what causes the warning, but I still don't quite
understand the warning.
If anyone could explain what I might be doing wrong, I'd be much obliged.
Bas Wassink.
I'm having trouble understanding a warning produced by 'splint', a
code-checker. The warning produced is:
keywords.c: (in function keyw_get_string)
keywords.c:60:31: Released storage Keywords[].Keyword reachable from global
A global variable does not satisfy its annotations when control
is transferred. (Use -globstate to inhibit warning)
keywords.c:60:11: Storage Keywords[].Keyword released
The line number isn't correct anymore since I snipped some 'irrelevant'
code. Here's the code that causes the warning:
/*
* keywords module for sta65xx, written by Bas Wassink
* started: 2005-09-13
* updated: 2005-09-16
*/
#include <string.h>
#include <stdio.h>
#include "globals.h" /* application wide used constants */
#include "keywords.h" /* prototypes and constants used */
struct keystruct { /* struct used by Keywords table */
char *Keyword;
int Id;
char *Description;
};
/* keywords table */
static struct keystruct Keywords[] = {
{ "byte", KEYW_BYTE, "data as bytes" },
{ "word", KEYW_WORD, "data as words" },
{ "text", KEYW_TEXT, "data as text" }
};
/* return keyword string */
char *keyw_get_string ( int k )
{
int i;
/* check identifier bounds */
if ( ( k >= KEYWORDS_AMOUNT ) || ( k < 0 ) )
return NULL;
/* look up Id in table */
for ( i = 0; i < KEYWORDS_AMOUNT; i++ )
if ( Keywords.Id == k )
return Keywords.Keyword; /* <= This causes the warning */
/* Id not found, return NULL as error code (shouldn't happen) */
return NULL;
}
I know I'm returning a pointer to memory accessible only by this module,
so that's probably what causes the warning, but I still don't quite
understand the warning.
If anyone could explain what I might be doing wrong, I'd be much obliged.
Bas Wassink.