![]() |
![]() |
#1 |
Registered User
Join Date: Jul 2008
Location: Poland
Posts: 666
|
Strange problem (or I'm stupid)
Code:
char *EditUrl(char *url) { InitApp(); ULONG sigs = 0; struct ObjApp * obj = CreateUrlApp(); STRPTR var; if (obj) { set(obj->STR_Url, MUIA_String_Contents, (ULONG*)url); while (DoMethod(obj->App, MUIM_Application_NewInput, (IPTR)&sigs) != MUIV_Application_ReturnID_Quit) { if (sigs) { sigs = Wait(sigs | SIGBREAKF_CTRL_C); if (sigs & SIGBREAKF_CTRL_C) break; } } get(obj->STR_Url, MUIA_String_Contents, &var); Printf(var); <--- this properly prints new address DisposeApp(obj); } return var; } int main(void) { Printf(EditUrl("www.google.com")); <--null only on <OS 3.5 ???? } |
![]() |
![]() |
#2 |
Registered User
Join Date: May 2010
Location: Helsinki, Finland
Posts: 1,341
|
I have no experience programming with MUI in particular, but most likely the return value "var" is no longer valid after you have called DisposeApp(obj).
And it's a bit risky anyway since you haven't initialized var at all, so you might return an uninitialized pointer from EditUrl() to printf(), in the case where obj = NULL. Last edited by ajk; 14 October 2016 at 10:52. |
![]() |
![]() |
#3 |
Registered User
Join Date: Jul 2008
Location: Poland
Posts: 666
|
You're right DisposeApp(obj) cleans var.
On OS3.9 and Aros, it works because of different memory managment, I guess. |
![]() |
![]() |
#4 |
Registered User
Join Date: May 2010
Location: Helsinki, Finland
Posts: 1,341
|
Indeed. You just need to make a copy of the data to somewhere that you manage yourself.
|
![]() |
![]() |
#5 | |
Registered User
Join Date: Jan 2002
Location: Germany
Posts: 7,032
|
Quote:
You should always run MungWall and Enforcer on your testing machines. MungWall will fill freed memory with garbage, so that you always stumble across orphaned strings (or pointers or ...). |
|
![]() |
![]() |
#6 |
Registered User
Join Date: Dec 2010
Location: Athens/Greece
Age: 53
Posts: 725
|
Minor nit-pick...
Printf in main should be Printf("%s\n", EditUrl("www.google.com")); |
![]() |
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
Thread Tools | |
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
strange problem with CWB 3.9 | cugar124 | project.ClassicWB | 1 | 11 March 2016 12:41 |
Very strange problem | Arnie | support.WinUAE | 5 | 26 February 2015 20:55 |
Stupid IFF 8SVX sample problem... | Amiga1992 | support.Apps | 16 | 01 August 2010 08:45 |
Strange problem | ami_junkie | support.Hardware | 0 | 30 April 2010 13:06 |
WinUAE strange problem- Please help. | Avanze | support.WinUAE | 2 | 21 January 2003 16:15 |
|
|