Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Memory problem when returning address of local variable #514

Open
wdeconinck opened this issue Oct 10, 2023 · 0 comments
Open

Memory problem when returning address of local variable #514

wdeconinck opened this issue Oct 10, 2023 · 0 comments

Comments

@wdeconinck
Copy link
Contributor

A worrying warning for following code in parms_map.c

int *parms_MapGlobalToLocal(parms_Map self, int gindex)
{
  int *lindex;
  
  if(self->isserial)
     lindex = &gindex;
  else
     lindex = parms_TableGet(self->table, gindex);
  
  return lindex;
}

The warning is:

/perm/nawd/fesom2/lib/parms/src/parms_map.c: In function ‘parms_MapGlobalToLocal’:
/perm/nawd/fesom2/lib/parms/src/parms_map.c:744:10: warning: function may return address of local variable [-Wreturn-local-addr]
   return lindex;
          ^~~~~~
/perm/nawd/fesom2/lib/parms/src/parms_map.c:735:49: note: declared here
 int *parms_MapGlobalToLocal(parms_Map self, int gindex)
                                             ~~~~^~~~~~

This happens in the assignment of the pointerlindex to &gindex in the first part of the if statement is problematic, as gindex is a temporary in this function.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant