ppisa commented on PR #19912:
URL: https://github.com/apache/nuttx/pull/19912#issuecomment-5560670422

   It is interesting, that my local build of the current mainline is without 
any warning with my local defconfig and even with qemu-intel64:mw defconfig. So 
it is probably specific for given GCC version.
   
   `lpTemplate` argument is of `LPCDLGTEMPLATE` type which is defined with
   ```
   #pragma pack(2)
   ```
   to match real MS Windows `DLGTEMPLATE` defined in 
[windlg.h](https://github.com/ghaerr/microwindows/blob/master/src/include/windlg.h)
 (and in `WINUSER.H` on MS Windows) which has to be aligned to `WORD`/16-bits 
and its size is  unfortunately unaligned to 32-bits. It is only 16-bit aligned. 
Matching `MWDLGTEMPLATE` defined in 
[include/winres.h](https://github.com/ghaerr/microwindows/blob/master/src/include/winres.h)
 is structure aligned regular way and solves continuation at right offset by 
char `extraData` field.
   
   It seems that affected `pDlg` pointer in `CreateDialogIndirectParam` is not 
stored for future use, it is really only source of parameters there and in 
`resGetDlgTemplExtra` function.
   
   So the state is, the problematic packing has to be kept for MS Windows 
compatibility, it originates in their 16-bit word. The access through 
`MWDLGTEMPLATE` is correct but the pointer can be unaligned (16-bi aligned). 
The data are used only to read parameters inside given function. There is no 
problem with the code on architectures which support unaligned access natively. 
There could be problem on more and more seldom architectures, i.e. 
Cortex-M0/M+/M1, all higher are OK. Te correct solution is to mark pointer to 
`MWDLGTEMPLATE` in `CreateDialogIndirectParam' and `resGetDlgTemplExtra` as 
unaligned or aligned to 16-bits to provide full guidance for C compiler how to 
deal with these on architectures not supporting unaligned data natively.
   
   Another easy solution is to define `MWDLGTEMPLATE`  with `pack(2)` as well.
   
   It is possible that there are little more similar problems which are given 
by providing Win API as one of the APIs variants.
   
   @ghaerr, please, do you have some opinion or preference there? It is no 
problem on any x86. It could be problem on some PowerPC, MIPS or old ARMs in 
past.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to