amagnasco / xwpe

Upload of an abandoned ncurses-based programming environment
http://www.identicalsoftware.com/xwpe/
GNU General Public License v2.0
29 stars 6 forks source link

we_menue.c returns a local automatic variable #30

Closed gbonnema closed 7 years ago

gbonnema commented 7 years ago

In we_menue.c shows the following code in lines 652 - 661:

OPTK WpeFillSubmenuItem(char *t, int x, char o, int(*fkt) ()) { OPTK optk ` optk.t = t optk.x = x optk.o = o return(optk) }`

Now this could lead to problems heavily depending on the OS and machine implementation. This function is used to create submenu items. As the memory was allocated and freed before use, there is no doubt this would lead to problems. Very dependant on OS.

This might have a relationship with issue #6 (F1 / Info menuoptions sometimes cause unexpected signal 11.).

I am looking into how to solve it. It depends on how it is used and how long the memory is necessary for. Will let you know if I have a solution (pull request).

gbonnema commented 7 years ago

This bug is based on a misunderstanding. C is perfectly capable of copying a struct. So return a local struct should end up in the intended target field.

Assigning a struct does a shallow copy, so pointers are copied, but the dereferenced pointers are not. Just a point of attention.

As this is not a bug, I will close the issue.