Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pointer arithmetic and parentheses elision #259

Open
jblachly opened this issue Aug 26, 2020 · 0 comments
Open

Pointer arithmetic and parentheses elision #259

jblachly opened this issue Aug 26, 2020 · 0 comments
Labels

Comments

@jblachly
Copy link

jblachly commented Aug 26, 2020

This was caught by our unit tests. Parentheses elision in #define macro to template conversion can lead to incorrect results when dealing with pointers.

This line:

#define bam_get_cigar(b) ((uint32_t*)((b)->data + (b)->core.l_qname))

Was translated by dstep to:

extern (D) auto bam_get_cigar(T)(auto ref T b)
{
    return cast(uint*) b.data + b.core.l_qname;
}

Pointer arithmetic rules cause this to give wrong result. Our original hand translation preserves parentheses, giving correct results:

extern (D) auto bam_get_cigar(bam1_t * b)
{
    return cast(uint*) ((*b).data + (*b).core.l_qname);
}

(b->data here is a ubyte *)

noted by @charlesgregory

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants