March 11, 2004 Array bug? | ||||
---|---|---|---|---|
| ||||
I have found this problem. (DMD 0.81) When I run this program with any arguments, it works as I expect. But without arguments, it seems to me, that the length property of array arg can not be queried. An exception is thrown. Is it a bug or am I completely confused? Best regards, Tamás (microwizard@ax.hu) --Results----------------------------- C:\Work\DottProp>dmd exctest.d C:\dmd\bin\..\..\dm\bin\link.exe exctest,,,user32+kernel32/noi; C:\Work\DottProp>exctest Debug 1. Debug 2. Error occured: Error: Access Violation C:\Work\DottProp>exctest kuka Debug 1. Debug 2. Debug 3. --exctest.d-------------------------------------------- void main(char[][] arg) { try { printf("Debug 1.\n"); if(!arg) { throw new Error("No args."); } printf("Debug 2.\n"); if(arg.length<2) { throw new Error("Nothing to do."); } printf("Debug 3.\n"); } catch(Error e) { printf("Error occured: %s ... Aborting.\n",e.toString()); } catch(Exception e) { printf("Exception occured: %s ... Aborting.\n",e.toString()); } catch { printf("Unexpected exception occured.\n"); } } --Finish------------------------------- |
March 11, 2004 Re: Array bug? | ||||
---|---|---|---|---|
| ||||
Posted in reply to MicroWizard | Nope, no array bug, printf() bug. Change your %s specifiers to %.*s and it works fine. This is because D's strings are of arbitrary length and not null-terminated. Your hint should have been that your "...Aborting" message never showed up in the error report. :)
-C. Sauls
-Invironz
MicroWizard wrote:
> I have found this problem. (DMD 0.81)
> When I run this program with any arguments, it works as I expect.
> But without arguments, it seems to me, that the length property of array arg can
> not be queried. An exception is thrown.
>
> Is it a bug or am I completely confused?
>
> Best regards,
> Tamás (microwizard@ax.hu)
>
> --Results-----------------------------
> C:\Work\DottProp>dmd exctest.d
> C:\dmd\bin\..\..\dm\bin\link.exe exctest,,,user32+kernel32/noi;
>
> C:\Work\DottProp>exctest
> Debug 1.
> Debug 2.
> Error occured: Error: Access Violation
>
> C:\Work\DottProp>exctest kuka
> Debug 1.
> Debug 2.
> Debug 3.
>
> --exctest.d--------------------------------------------
> void main(char[][] arg)
> {
> try
> {
> printf("Debug 1.\n");
> if(!arg)
> {
> throw new Error("No args.");
> }
> printf("Debug 2.\n");
> if(arg.length<2)
> {
> throw new Error("Nothing to do.");
> }
> printf("Debug 3.\n");
> }
> catch(Error e)
> {
> printf("Error occured: %s ... Aborting.\n",e.toString());
> }
> catch(Exception e)
> {
> printf("Exception occured: %s ... Aborting.\n",e.toString());
> }
> catch
> {
> printf("Unexpected exception occured.\n");
> }
> }
> --Finish-------------------------------
|
Copyright © 1999-2021 by the D Language Foundation