D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 22976 - importC: fails to multiply by element size when doing address-of
Summary: importC: fails to multiply by element size when doing address-of
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: All All
: P1 normal
Assignee: No Owner
URL:
Keywords: ImportC, pull, wrong-code
Depends on:
Blocks:
 
Reported: 2022-04-03 05:27 UTC by duser
Modified: 2022-04-18 06:19 UTC (History)
2 users (show)

See Also:


Attachments
fix (1.02 KB, patch)
2022-04-17 22:29 UTC, duser
Details | Diff

Note You need to log in before you can comment on or make changes to this issue.
Description duser 2022-04-03 05:27:14 UTC
struct S { unsigned short xs[2]; };
struct S s1 = { { 0xabcd, 0x1234 } };
struct S *sp = &s1;

int printf(char *, ...);

int main()
{
	unsigned short *xp = &sp->xs[1];
	printf("%hx\n", *xp); // 34ab

	unsigned short x = sp->xs[1];
	printf("%hx\n", x); // 1234

	return 0;
}

introduced in https://github.com/dlang/dmd/pull/13925
Comment 1 Walter Bright 2022-04-05 07:54:59 UTC
Probably forgot to multiply by sizeof.
Comment 2 duser 2022-04-17 22:29:45 UTC
Created attachment 1846 [details]
fix

attaching my patch i've been using that fixes this
Comment 3 Dlang Bot 2022-04-18 05:21:20 UTC
@WalterBright created dlang/dmd pull request #14005 "fix Issue 22976 - importC: fails to multiply by element size when doi…" fixing this issue:

- fix Issue 22976 - importC: fails to multiply by element size when doing address-of

https://github.com/dlang/dmd/pull/14005
Comment 4 Dlang Bot 2022-04-18 06:19:43 UTC
dlang/dmd pull request #14005 "fix Issue 22976 - importC: fails to multiply by element size when doi…" was merged into master:

- 1f561d908198c96e62b899370d16f4b4588da05d by Walter Bright:
  fix Issue 22976 - importC: fails to multiply by element size when doing address-of

https://github.com/dlang/dmd/pull/14005