Skip to content

Commit 9a6c536

Browse files
committed
Add support for float and double operands in TrapWriter
TrapWriter now handles float and double values, ensuring they are written with a decimal point for correct CodeQL parsing. Related database files for double operands have been added.
1 parent 996788d commit 9a6c536

4 files changed

Lines changed: 24 additions & 0 deletions

File tree

binary/extractor/cil/Semmle.Extraction.CSharp.IL/Trap/TrapWriter.cs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,12 @@ private void WriteValue(object value) {
5454
case long l:
5555
writer.Write(l);
5656
break;
57+
case float f:
58+
WriteFloat(f);
59+
break;
60+
case double d:
61+
WriteDouble(d);
62+
break;
5763
case string s:
5864
// Escape string and wrap in quotes
5965
writer.Write('"');
@@ -69,6 +75,24 @@ private void WriteValue(object value) {
6975
}
7076
}
7177

78+
private void WriteFloat(float f) {
79+
// Use InvariantCulture to ensure decimal point is '.' not ','
80+
var str = f.ToString("G", System.Globalization.CultureInfo.InvariantCulture);
81+
writer.Write(str);
82+
// Ensure there's always a decimal point so CodeQL parses it as a float
83+
if (!str.Contains('.') && !str.Contains('E') && !str.Contains('e'))
84+
writer.Write(".0");
85+
}
86+
87+
private void WriteDouble(double d) {
88+
// Use InvariantCulture to ensure decimal point is '.' not ','
89+
var str = d.ToString("G", System.Globalization.CultureInfo.InvariantCulture);
90+
writer.Write(str);
91+
// Ensure there's always a decimal point so CodeQL parses it as a float
92+
if (!str.Contains('.') && !str.Contains('E') && !str.Contains('e'))
93+
writer.Write(".0");
94+
}
95+
7296
private string EscapeString(string s) {
7397
// Basic escaping - may need to be more sophisticated
7498
return s.Replace("\\", "\\\\")

binary/oatDB/db-cil/default/cache/is-trimmed

Whitespace-only changes.
41 Bytes
Binary file not shown.
30 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)