English Amiga Board


Go Back   English Amiga Board > Coders > Coders. General

 
 
Thread Tools
Old 14 October 2016, 10:28   #1
arti
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 ????
}
arti is offline  
Old 14 October 2016, 10:46   #2
ajk
Registered User
 
ajk's Avatar
 
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.
ajk is offline  
Old 14 October 2016, 10:58   #3
arti
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.
arti is offline  
Old 14 October 2016, 11:09   #4
ajk
Registered User
 
ajk's Avatar
 
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.
ajk is offline  
Old 14 October 2016, 18:07   #5
thomas
Registered User
 
thomas's Avatar
 
Join Date: Jan 2002
Location: Germany
Posts: 7,032
Quote:
Originally Posted by arti View Post
You're right DisposeApp(obj) cleans var.

On OS3.9 and Aros, it works because of different memory managment, I guess.

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 ...).
thomas is offline  
Old 14 October 2016, 19:10   #6
alkis
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"));
alkis is offline  
 


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Similar Threads
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

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 07:24.

Top

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Page generated in 0.07445 seconds with 15 queries