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

support search for label #90

Open
wmliang opened this issue Dec 14, 2023 · 1 comment
Open

support search for label #90

wmliang opened this issue Dec 14, 2023 · 1 comment

Comments

@wmliang
Copy link

wmliang commented Dec 14, 2023

Is it possible to search label in C/C++ ?

I tried

weggli '{
abc:
}' ~/project

but it got

Error! Query parsing failed: {
abc: [MISSING ; ]
}

I understand it will overlap with the not: and strict: function.

@bluec0re
Copy link
Contributor

You can search for labels but not for a label: weggli '{ abc:; }' ~/project works for example, but will return the first label in a file (not the first label named abc). Looks like this is because the label name is not used as a pattern here. Might be just an oversight, but will definitely conflict with not: etc.

example:

test.c

void func_with_label()
{
    if ((err = SSLHashSHA1.update(&hashCtx, &signedParams)) != 0)
        goto fail;
        goto fail;

	err = sslRawVerify(ctx,
                       ctx->peerPubKey,
                       dataToSign,				/* plaintext */
                       dataToSignLen,			/* plaintext length */
                       signature,
                       signatureLen);

fail:
    SSLFreeBuffer(&signedHashes);
    SSLFreeBuffer(&hashCtx);
    return err;

}

void func_without_label()
{
    if ((err = SSLHashSHA1.update(&hashCtx, &signedParams)) != 0)
        goto fail;
        goto fail;

	err = sslRawVerify(ctx,
                       ctx->peerPubKey,
                       dataToSign,				/* plaintext */
                       dataToSignLen,			/* plaintext length */
                       signature,
                       signatureLen);
}

this matches only func_with_label

$ weggli '{   
 goto $x; goto $x; foo: _;
}' /tmp/test.c

/tmp/test.c:1
void func_with_label()
{
    if ((err = SSLHashSHA1.update(&hashCtx, &signedParams)) != 0)
        goto fail;
        goto fail;

	err = sslRawVerify(ctx,
                       ctx->peerPubKey,
                       dataToSign,				/* plaintext */
                       dataToSignLen,			/* plaintext length */
..
}

while this matches both:

$ weggli '{
 goto $x; goto $x;        
}' /tmp/test.c

/tmp/test.c:1
void func_with_label()
{
    if ((err = SSLHashSHA1.update(&hashCtx, &signedParams)) != 0)
        goto fail;
        goto fail;

	err = sslRawVerify(ctx,
                       ctx->peerPubKey,
                       dataToSign,				/* plaintext */
                       dataToSignLen,			/* plaintext length */
..
}
/tmp/test.c:21
void func_without_label()
{
    if ((err = SSLHashSHA1.update(&hashCtx, &signedParams)) != 0)
        goto fail;
        goto fail;

	err = sslRawVerify(ctx,
                       ctx->peerPubKey,
                       dataToSign,				/* plaintext */
                       dataToSignLen,			/* plaintext length */
..
}

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

No branches or pull requests

2 participants