weggli icon indicating copy to clipboard operation
weggli copied to clipboard

support search for label

Open wmliang opened this issue 2 years ago • 1 comments

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.

wmliang avatar Dec 14 '23 22:12 wmliang

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 */
..
}

bluec0re avatar Jan 30 '24 08:01 bluec0re