You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
| `range` | Verify value is within range | `kind`, `target` (arg, return_value, or symbol), `range` (with `min` and `max`) | `symbol` | Input validation, bounds |
695
+
696
+
#### Quick Reference: Field Requirements by Predicate Kind
**Legend**: ✓ = Required, ✗ = Not allowed/Not used, Optional = May be included
707
+
708
+
**Important Notes:**
709
+
- **`nonnull`**: Only set `target` to an argument (e.g., `arg0`) or `return_value`. The `symbol` field is optional for documentation purposes.
710
+
- **`relation`**: Must specify `target`, `relation` operator, and `value` to compare against. Target can be an argument, return value, or symbol reference.
711
+
- **`alignment`**: Must specify `target` and `align` (alignment in bytes). Typically used with pointer arguments.
712
+
- **`expr`**: Only requires the `expr` field with a free-form expression string. Target and symbol are optional for context.
713
+
- **`range`**: Must specify `target` and a `range` object with both `min` and `max` values.
714
+
- **`symbol`**: This field is always optional and serves as a descriptive reference to document what variable or symbol the predicate refers to.
715
+
716
+
#### Target Specification
717
+
718
+
The `target` field specifies what the predicate applies to:
719
+
720
+
- **`arg0`, `arg1`, etc.**: Function arguments (0-indexed)
721
+
- **`return_value`**: Return value of the function
722
+
- **`symbol`**: A named symbol (requires `symbol` field)
723
+
724
+
#### Relation Types
725
+
726
+
For `relation` kind predicates:
727
+
728
+
| Relation | Operators | Description |
729
+
|----------|-----------|-------------|
730
+
| `eq` | `==` | Equal to |
731
+
| `neq` | `!=` | Not equal to |
732
+
| `lt` | `<` | Less than |
733
+
| `lte` | `<=` | Less than or equal to |
734
+
| `gt` | `>` | Greater than |
735
+
| `gte` | `>=` | Greater than or equal to |
736
+
| `none` | - | No relation (for existence checks) |
737
+
738
+
### Static Contract Examples
739
+
740
+
#### Example 1: Non-null Pointer Check (nonnull)
741
+
742
+
```yaml
743
+
preconditions:
744
+
- id: "ptr_nonnull"
745
+
description: "USB device pointer must not be null"
746
+
pred:
747
+
kind: "nonnull"
748
+
target: "arg0"
749
+
symbol: "usb_device" # Optional: for documentation
750
+
```
751
+
752
+
**Required fields for `nonnull`**: `kind`, `target`
753
+
754
+
#### Example 2: Range Validation (range)
755
+
756
+
```yaml
757
+
preconditions:
758
+
- id: "size_range"
759
+
description: "Buffer size must be within valid range"
760
+
pred:
761
+
kind: "range"
762
+
target: "arg1"
763
+
range:
764
+
min: "0"
765
+
max: "USB_MAX_PACKET_SIZE"
766
+
symbol: "buffer_size" # Optional: for documentation
767
+
```
768
+
769
+
**Required fields for `range`**: `kind`, `target`, `range` (with `min` and `max`)
770
+
771
+
#### Example 3: Comparison Relation (relation)
772
+
773
+
```yaml
774
+
preconditions:
775
+
- id: "size_positive"
776
+
description: "Size must be greater than zero"
777
+
pred:
778
+
kind: "relation"
779
+
target: "arg1"
780
+
relation: "gt"
781
+
value: "0"
782
+
symbol: "size" # Optional: for documentation
783
+
```
784
+
785
+
**Required fields for `relation`**: `kind`, `target`, `relation`, `value`
786
+
787
+
#### Example 4: Memory Alignment (alignment)
788
+
789
+
```yaml
790
+
preconditions:
791
+
- id: "buffer_aligned"
792
+
description: "Buffer must be 4-byte aligned"
793
+
pred:
794
+
kind: "alignment"
795
+
target: "arg0"
796
+
align: "4"
797
+
symbol: "buffer" # Optional: for documentation
798
+
```
799
+
800
+
**Required fields for `alignment`**: `kind`, `target`, `align`
801
+
802
+
#### Example 5: Complex Expression (expr)
803
+
804
+
```yaml
805
+
preconditions:
806
+
- id: "device_valid"
807
+
description: "USB device must be in configured state"
0 commit comments