Asl.library FileRequester crashes when selected assign/volume doesn't exist

12 posts / 0 new
Last post
blmara
blmara's picture
Offline
Last seen: 2 years 2 months ago
Joined: 2013-10-31 00:20
Asl.library FileRequester crashes when selected assign/volume doesn't exist
Hi, in my program I use Asl file requester both through IASL->AslRequestTags and through getfile.gadget functions. I noticed that for some reason, both ways lead to crash if I give non-existing volume name to either ASLFR_InitialDrawer or entering such in the file requester Drawer field. If entering only non-existing drawer name (without volume name like Test:) causes fr to ask whether one should create a new drawer, as it should. I extracted my Asl code to the file above. This code, however, doesn't crash but ask for reassignment as it should. I'm quite puzzled what's causing this. Would the GR log help to understand the problem. BTW, I don't have any global library bases stored in my program but using only the interfaces, would this affect asl.library? I'm using AmigaOne X1000, OS41FE, the kernel.debug is effective. Extracted code (which, runned separately, doesn't crash!)
  1. #include <proto/asl.h>
  2. #include <proto/dos.h>
  3. #include <proto/exec.h>
  4. #include <libraries/asl.h>
  5. #include "string.h"
  6.  
  7. /*
  8. ** compiled with:
  9. ** vc aslproblem.c -o ram:aslproblem +newlib
  10. */
  11.  
  12. struct AslIFace *IAsl;
  13. struct FileRequester *FileReq;
  14. struct Library *base;
  15. STRPTR Testname = "Test:testing";
  16.  
  17. int main(int ac,char *av[])
  18. {
  19. STRPTR docname,dirname;
  20. int dirlen;
  21.  
  22. if (base = IExec->OpenLibrary("asl.library",53L))
  23. {
  24. if (IAsl = (struct AslIFace *)IExec->GetInterface(base,"main",1,NULL))
  25. {
  26. FileReq = IAsl->AllocAslRequestTags(ASL_FileRequest,
  27. ASLFR_StayOnTop,TRUE,
  28. ASLFR_RejectIcons,TRUE,
  29. ASLFR_PrivateIDCMP,TRUE,
  30. ASLFR_SleepWindow,TRUE,
  31. ASLFR_DoPatterns,TRUE,
  32. TAG_DONE);
  33. dirlen = IDOS->FilePart(Testname) - Testname;
  34. if (dirname = IExec->AllocVecTags(dirlen+1,TAG_DONE))
  35. {
  36. strncpy(dirname,Testname,dirlen);
  37. *(dirname+dirlen) = '\0'; /* note: strncpy doesn't put NUL if strlen(Testname) > dirlen! */
  38. }
  39. if (FileReq)
  40. {
  41. IAsl->AslRequestTags(FileReq,
  42. ASLFR_TitleText,"Testing!",
  43. ASLFR_InitialDrawer,dirname,
  44. ASLFR_InitialFile,IDOS->FilePart(Testname),
  45. ASLFR_InitialPattern,"(#?.xml|#?.mxl)",
  46. ASLFR_DoSaveMode,TRUE,
  47. TAG_DONE);
  48. IAsl->FreeAslRequest(FileReq);
  49. }
  50. if (dirname)
  51. IExec->FreeVec(dirname);
  52. IExec->DropInterface((struct Interface *)IAsl);
  53. }
  54. IExec->CloseLibrary(base);
  55. }
  56. return(0);
  57. }
and GR log through Sashimi (here, the SaveAsDoc() is the routine calling AslRequestTags. Note that requester starts properly. Crash comes when one enters the non-existing Test: volume name into Drawer field of requester.
  1. "DEVS:lpr.device" Hunk 0000 Offset 00000000 (SegList: 0x1658912d)
  2. ADDR: 6ffb8700 9126bc00 00000000 00000000 00000000 00000000 00000000 57cc1150
  3. Page information:
  4. Page not found
  5.  
  6.  
  7. [_impl_AddTask] Adding Task 0x596241b0, Background CLI (0x5a6302a0)
  8. [_impl_AddTask] Task = 0x596241b0, ETask = 0xdfb47e50, Context = 0xdfb9e3e0
  9. [_impl_AddTask] Stack bottom = 0x5e3e9038, Stack top = 0x5e3ed024, Stack pointer = 0x5e3ecff0
  10. [_impl_AddTask] Task added to ready list
Marko
xenic
xenic's picture
Offline
Last seen: 3 months 1 week ago
Joined: 2011-05-07 04:52
Re: Asl.library FileRequester crashes when selected assign...
Without the ability to reproduce the crash, I can't help but maybe someone else can. However, I can comment on an unrelated issue in your example code. I don't think you will need line 37and the accompanying comment if you replace strncpy() with strlcpy(). Here is one of many explanations you can find by googling strlcpy: https://en.wikibooks.org/wiki/C_Programming/C_Reference/nonstandard/strlcpy
X1000 - OS 4.1FE
blmara
blmara's picture
Offline
Last seen: 2 years 2 months ago
Joined: 2013-10-31 00:20
Re: Asl.library FileRequester crashes when selected assign...
@xenic Thanks, I actually found this link also while wondering why my drawer names looked so odd ;-> Marko
Marko
jabirulo
jabirulo's picture
Offline
Last seen: 18 hours 40 min ago
Joined: 2013-05-30 00:53
Re: Asl.library FileRequester crashes when selected assign...
and if you put hardcoded drawer and filename does it crash too?
  1. ASLFR_InitialDrawer, "Test:",
  2. ASLFR_InitialFile, "testing",
AOS4.1/SAM460ex/PPC460EX-1155MHZ/2048MB/RadeonHD6570/SSD120GB/DVDRW :-P
salass00
salass00's picture
Offline
Last seen: 1 week 6 days ago
Joined: 2011-02-03 11:27
Re: Asl.library FileRequester crashes when selected assign...
Given that the number of characters to copy is known it would be more efficient to just replace strncpy() with memcpy(). BTW I tried writing a phony volume name in both a file requester (both normal and save type) and in a getfile gadget but I wasn't able to make it crash like this on my AmigaOS 4.1 beta install.
hypex
hypex's picture
Offline
Last seen: 3 weeks 1 day ago
Joined: 2011-09-09 16:20
Re: Asl.library FileRequester crashes when selected assign...
If you want to be consistent in your code you could use malloc() or calloc() if you like it cleared. You said you don't store global library bases but where do you put them? For your own use you only need the interface pointer. But the library base will need to be opened obviously and closed later. This begs the question. You extracted code that works by itself. But what do you do with the library base? Is your code single threaded? You open ASL library and interface from one task and call it from that one task? Otherwise you can get into trouble.
blmara
blmara's picture
Offline
Last seen: 2 years 2 months ago
Joined: 2013-10-31 00:20
Re: Asl.library FileRequester crashes when selected assign...
@jabirulo Yes, it crashes then too. Marko
Marko
blmara
blmara's picture
Offline
Last seen: 2 years 2 months ago
Joined: 2013-10-31 00:20
Re: Asl.library FileRequester crashes when selected assign...
@hypex Single threaded currently. I use these routines at start and end of my program to make opening/closing libraries (and Reaction classes with slightly modified code) more compact and the possible error message output esier. So, the library base needed when closing a library is captured from struct Interface.
  1. struct Interface *InitIface(STRPTR libname,ULONG libversion,STRPTR ifacename,ULONG ifaceversion)
  2. {
  3. struct Interface *iface = NULL;
  4. struct Library *base;
  5.  
  6. /*
  7. ** Opens a global interface of a library. Note that the library base
  8. ** is not saved to global library base variable anymore (see SDK 53.24
  9. ** release FAQ.
  10. **
  11. ** IExec and IDOS are opened by compiler code automatically.
  12. ** application.library's lib base is obtained from IApplication
  13. ** if it has been already GetInterface()'d to avoid double opening.
  14. **
  15. ** Note that if a different thread/task uses the same interface, it
  16. ** has to do a iface->Obtain()---iface->Release() pair see autodoc
  17. ** of IExec->GetInterface().
  18. */
  19. if (ifacename == prefsifacename)
  20. base = IApplication->Data.LibBase;
  21. else
  22. base = IExec->OpenLibrary(libname,libversion);
  23.  
  24. if (base)
  25. {
  26. if (iface = IExec->GetInterface(base,ifacename,ifaceversion,NULL))
  27. {
  28. /* ok */
  29. }
  30. else
  31. if (ifacename != prefsifacename) /* don't close application.library if prefsobjects interface failed */
  32. IExec->CloseLibrary(base);
  33. }
  34.  
  35. if (iface == NULL)
  36. ErrorCode = MSG_ERROR_LIBRARYWONTOPEN;
  37. return(iface);
  38. }
  39.  
  40. void CloseIFace(struct Interface *iface)
  41. {
  42. struct Library *base;
  43.  
  44. /*
  45. ** Drops interface and closes a library
  46. ** Doesn't close library if application.library's IPrefsObject cause still in use
  47. */
  48. if (iface)
  49. {
  50. base = iface->Data.LibBase;
  51. IExec->DropInterface(iface);
  52. if (iface != (struct Interface *)IPrefsObjects)
  53. IExec->CloseLibrary(base);
  54. }
  55. }
Marko
hypex
hypex's picture
Offline
Last seen: 3 weeks 1 day ago
Joined: 2011-09-09 16:20
Re: Asl.library FileRequester crashes when selected assign...
@blmara Okay I can understand now. I've considered doing something similar myself. I thought shortcuts may be standardised but so far looks like we are still on our own. For example I had this idea to give standard Amiga libraries ID numbers so that a table could be built up with the ones you want. And possibly passing the pointer addresses as well but automating it would be good. Anyway will do some tests when I'm on OS4 next. If the base and interface pointer are correctly initialised then there should be no problem. But youy never know until you find it. :-)
hypex
hypex's picture
Offline
Last seen: 3 weeks 1 day ago
Joined: 2011-09-09 16:20
Re: Asl.library FileRequester crashes when selected assign...
Three things come to mind. Your library opening code is different for a start. That may cause an issue. It's possible dirname could be a rogue string. I've had random corruption when not all characters were cleared and I used "hacks" to poke EOL bytes in. In your bad code try clearing the whole string before copying. In your good code fil lit with "rogue" chars before your copy. Passing patterns to file requester. I've had trouble with this and it may have only been on OS4 I noticed or when it crashed. It's only mentioned for ASLFR_RejectPattern and ASLFR_AcceptPattern but according to that ParsePatternNoCase() must be used when passing a pattern. And a normal pattern string is not acceptable.
blmara
blmara's picture
Offline
Last seen: 2 years 2 months ago
Joined: 2013-10-31 00:20
Re: Asl.library FileRequester crashes when selected assign...
@hypex Thanks, I tried something: - put up a normal AslBase - cleared the dirname buffer with memset() - removed InitialPattern These didn't help, crashed if I put Test: to drawer gadget. Still wondering. Marko
Marko
thomas
thomas's picture
Offline
Last seen: 4 days 18 hours ago
Joined: 2011-05-16 14:23
Re: Asl.library FileRequester crashes when selected assign...
Well, it obviously crashes when trying to show the "please inset volume Test in any drive" requester. It runs through IPrefs, requester.class and crashes somewhere in intuition.library. So the question is, did you do something to the standard environment? Did you change the default public screen? Did you do something to your Process->pr_WindowPtr? What about ASLFR_Window and ASLFR_Screen? Do you supply these and are they valid window resp. screen pointers? In your above example you put ASLFR_SleepWindow,TRUE which does not make any sense without a ASLFR_Window. Did you actually read up all the tags you are using and did you understand what they are good for? You should make an example which uses *exactly* the code from your crashing program. I.e. keep the SaveAsDoc routine as is, just add a new main() routine as a test driver.
Log in or register to post comments