Pelles C > Feature requests

Optimizer

<< < (2/3) > >>

John Z:
Thanks for the help frankie!

Some more evidence for a memory issue:
I removed all optimizations then added by #pragma only optimizing the one procedure.
The 'bug' was there as expected.

You might recall from above that un-optimized and optimized file2 objs were different by about 58 bytes.
so I changed
wchar_t szFileName[MAX_PATH];
into
wchar_t szFileName[MAX_PATH+57];

The problem went away!  Less than +57 it is back .....
interestingly adding in a new variable k[57] though didn't fix it.

These memory issues are very hard to find....no really good free tools that I know of either,
just tedious detailed examinations ....

Say - what disassembler did you use?

Thanks again,

John Z

frankie:
John I don't think this issue is related to optimization problem or other memory issue.
Looking at source there is no apparent error.
MS docs states that the function can return false if:

--- Quote --- <link>...
If the buffer is too small, the function returns FALSE and the CommDlgExtendedError function returns FNERR_BUFFERTOOSMALL. In this case, the first two bytes of the lpstrFile buffer contain the required size, in bytes or characters.

--- End quote ---
This behavior is consistent with the widening of the buffer.
Another problem is related to the buffer that should be initialized as empty, but you don't do it. From MS documentation above:

--- Quote ---The file name used to initialize the File Name edit control. The first character of this buffer must be NULL if initialization is not necessary. When the GetOpenFileName or GetSaveFileName function returns successfully, this buffer contains the drive designator, path, file name, and extension of the selected file.

--- End quote ---
You can set it as follows:

--- Code: ---wchar_t szFileName[MAX_PATH] = {0};
--- End code ---


--- Quote from: John Z on September 17, 2023, 03:12:35 PM ---Thanks for the help frankie!
Say - what disassembler did you use?
John Z

--- End quote ---
I used pedump.exe from PellesC suite  ;)

John Z:
Thanks frankie!

I'm going to give the CommDlgExtendedError function a try.  I tried the easy GetLastError() which probably was not enough.

I'll zero out the space as you suggest and the doc shows I should, I missed that.  The only caveat is that I use essentially the exact same procedure sequence in 6 other places and also with GetSaveFileNameW.  Optimizing those has not shown any issues.  Nevertheless always best to do it 'right'  :)

Thanks for the podump tip! I guess I need to investigate the Pelles BIN directory a bit more ....

Back to the code .....

Appreciate all the help very much! 

John Z

John Z:

--- Quote from: frankie on September 17, 2023, 03:58:20 PM ---Another problem is related to the buffer that should be initialized as empty, but you don't do it. From MS documentation above:

The file name used to initialize the File Name edit control. The first character of this buffer must be NULL if initialization is not necessary. When the GetOpenFileName or GetSaveFileName function returns successfully, this buffer contains the drive designator, path, file name, and extension of the selected file.

You can set it as follows:

--- Code: ---wchar_t szFileName[MAX_PATH] = {0};
--- End code ---

--- End quote ---

frankie - THANK YOU SO MUCH!  I wish I could buy you a beer or a KEG!

I first used DWORD err= CommDlgExtendedError(); it showed
FNERR_INVALIDFILENAME
0x3002  A file name is invalid.

Then as you said I set wchar_t szFileName[MAX_PATH] = {0};
Problem solved!!! Works perfectly with optimization.  I'll fix the other incidences too.

I really, really, appreciate you sharing your expertise and knowledge!  You saved me innumerable hours and grief.

Thanks very much!

John Z

Update:  All the other incidences worked because I immediately set the filename to  szFileName before it was used.  So all consistent.

frankie:
You're welcome.
Cheers!!!  ;)

  .   *   ..  . *  *
*  * @()Ooc()*   o  .
    (Q@*0CG*O()  ___
   |\_________/|/ _ \
   |  |  |  |  | / | |
   |  |  |  |  | | | |
   |  |  |  |  | | | |
   |  |  |  |  | | | |
   |  |  |  |  | | | |
   |  |  |  |  | \_| |
   |  |  |  |  |\___/
   |\_|__|__|_/|
    \_________/


P.S. The unptimized code probably worked because the filename storage was in a stack address containing zeroes at beginning (NULL string).
Also this should work:

--- Code: ---wchar_t szFileName[MAX_PATH];
szFileName[0] = '\0';

--- End code ---

Navigation

[0] Message Index

[#] Next page

[*] Previous page

Go to full version