Skip to content

Commit 727c19c

Browse files
committed
Fix bug with empty struct tags
1 parent 48d53f4 commit 727c19c

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

go/ql/lib/semmle/go/Types.qll

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -470,7 +470,7 @@ class ByteSliceType extends SliceType {
470470
// by unpacking the first 5 fields and tags, allowing a single join
471471
// to strongly constrain the available candidates.
472472
private predicate hasComponentTypeAndTag(StructType s, int i, string name, Type tp, string tag) {
473-
component_types(s, i, name, tp) and struct_tags(s, i, tag)
473+
component_types(s, i, name, tp) and tag = getStructTag(s, i)
474474
}
475475

476476
private newtype TOptStructComponent =
@@ -554,6 +554,14 @@ private predicate unpackAndUnaliasStructType(
554554
)
555555
}
556556

557+
bindingset[i]
558+
pragma[inline]
559+
private string getStructTag(StructType st, int i) {
560+
struct_tags(st, i, result)
561+
or
562+
not struct_tags(st, i, _) and result = ""
563+
}
564+
557565
/** A struct type. */
558566
class StructType extends @structtype, CompositeType {
559567
/**
@@ -582,12 +590,7 @@ class StructType extends @structtype, CompositeType {
582590
* Note that this predicate does not take promoted fields into account.
583591
*/
584592
predicate hasOwnFieldWithTag(int i, string name, Type tp, boolean isEmbedded, string tag) {
585-
this.hasOwnField(i, name, tp, isEmbedded) and
586-
(
587-
struct_tags(this, i, tag)
588-
or
589-
not struct_tags(this, i, _) and tag = ""
590-
)
593+
this.hasOwnField(i, name, tp, isEmbedded) and tag = getStructTag(this, i)
591594
}
592595

593596
/**

0 commit comments

Comments
 (0)