Skip to content

Commit 13950d0

Browse files
authored
Merge pull request #661 from jwest115/fprime-2966
Check for negative port numbers
2 parents d7fb2e2 + 11f4b60 commit 13950d0

File tree

78 files changed

+5183
-5183
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

78 files changed

+5183
-5183
lines changed

compiler/lib/src/main/scala/codegen/CppWriter/ComponentCppWriter/ComponentInputPorts.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ case class ComponentInputPorts(
5555
CppDoc.Type(s"${getQualifiedPortTypeName(p, PortInstance.Direction.Input)}*"),
5656
lines(
5757
s"""|FW_ASSERT(
58-
| portNum < this->${numGetterName(p)}(),
58+
| (0 <= portNum) && (portNum < this->${numGetterName(p)}()),
5959
| static_cast<FwAssertArgType>(portNum)
6060
|);
6161
|
@@ -229,7 +229,7 @@ case class ComponentInputPorts(
229229
lines(
230230
s"""|// Make sure port number is valid
231231
|FW_ASSERT(
232-
| portNum < this->${portNumGetterName(p)}(),
232+
| (0 <= portNum) && (portNum < this->${portNumGetterName(p)}()),
233233
| static_cast<FwAssertArgType>(portNum)
234234
|);
235235
|"""

compiler/lib/src/main/scala/codegen/CppWriter/ComponentCppWriter/ComponentOutputPorts.scala

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ case class ComponentOutputPorts(
4848
CppDoc.Type("void"),
4949
lines(
5050
s"""|FW_ASSERT(
51-
| portNum < this->${numGetterName(p)}(),
51+
| (0 <= portNum) && (portNum < this->${numGetterName(p)}()),
5252
| static_cast<FwAssertArgType>(portNum)
5353
|);
5454
|
@@ -109,7 +109,7 @@ case class ComponentOutputPorts(
109109
CppDoc.Type("void"),
110110
lines(
111111
s"""|FW_ASSERT(
112-
| portNum < this->${portNumGetterName(p)}(),
112+
| (0 <= portNum) && (portNum < this->${portNumGetterName(p)}()),
113113
| static_cast<FwAssertArgType>(portNum)
114114
|);
115115
|
@@ -143,7 +143,7 @@ case class ComponentOutputPorts(
143143
List.concat(
144144
lines(
145145
s"""|FW_ASSERT(
146-
| portNum < this->${portNumGetterName(p)}(),
146+
| (0 <= portNum) && (portNum < this->${portNumGetterName(p)}()),
147147
| static_cast<FwAssertArgType>(portNum)
148148
|);
149149
|
@@ -188,7 +188,7 @@ case class ComponentOutputPorts(
188188
CppDoc.Type("bool"),
189189
lines(
190190
s"""|FW_ASSERT(
191-
| portNum < this->${numGetterName(p)}(),
191+
| (0 <= portNum) && (portNum < this->${numGetterName(p)}()),
192192
| static_cast<FwAssertArgType>(portNum)
193193
|);
194194
|

compiler/lib/src/main/scala/codegen/CppWriter/ComponentCppWriter/TestWriter/ComponentTesterBaseWriter.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -437,7 +437,7 @@ case class ComponentTesterBaseWriter(
437437
lines(
438438
s"""|// Make sure port number is valid
439439
|FW_ASSERT(
440-
| portNum < this->${testerPortNumGetterName(p)}(),
440+
| (0 <= portNum) && (portNum < this->${testerPortNumGetterName(p)}()),
441441
| static_cast<FwAssertArgType>(portNum)
442442
|);
443443
|
@@ -477,7 +477,7 @@ case class ComponentTesterBaseWriter(
477477
lines(
478478
s"""|// Make sure port number is valid
479479
|FW_ASSERT(
480-
| portNum < this->${testerPortNumGetterName(p)}(),
480+
| (0 <= portNum) && (portNum < this->${testerPortNumGetterName(p)}()),
481481
| static_cast<FwAssertArgType>(portNum)
482482
|);
483483
|

compiler/tools/fpp-to-cpp/test/component/base/ActiveAsyncProductPortsOnlyComponentAc.ref.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ Fw::InputDpResponsePort* ActiveAsyncProductPortsOnlyComponentBase ::
153153
get_productRecvIn_InputPort(FwIndexType portNum)
154154
{
155155
FW_ASSERT(
156-
portNum < this->getNum_productRecvIn_InputPorts(),
156+
(0 <= portNum) && (portNum < this->getNum_productRecvIn_InputPorts()),
157157
static_cast<FwAssertArgType>(portNum)
158158
);
159159

@@ -171,7 +171,7 @@ void ActiveAsyncProductPortsOnlyComponentBase ::
171171
)
172172
{
173173
FW_ASSERT(
174-
portNum < this->getNum_productRequestOut_OutputPorts(),
174+
(0 <= portNum) && (portNum < this->getNum_productRequestOut_OutputPorts()),
175175
static_cast<FwAssertArgType>(portNum)
176176
);
177177

@@ -185,7 +185,7 @@ void ActiveAsyncProductPortsOnlyComponentBase ::
185185
)
186186
{
187187
FW_ASSERT(
188-
portNum < this->getNum_productSendOut_OutputPorts(),
188+
(0 <= portNum) && (portNum < this->getNum_productSendOut_OutputPorts()),
189189
static_cast<FwAssertArgType>(portNum)
190190
);
191191

@@ -205,7 +205,7 @@ void ActiveAsyncProductPortsOnlyComponentBase ::
205205
)
206206
{
207207
FW_ASSERT(
208-
portNum < this->getNum_productRequestOut_OutputPorts(),
208+
(0 <= portNum) && (portNum < this->getNum_productRequestOut_OutputPorts()),
209209
static_cast<FwAssertArgType>(portNum)
210210
);
211211

@@ -219,7 +219,7 @@ void ActiveAsyncProductPortsOnlyComponentBase ::
219219
)
220220
{
221221
FW_ASSERT(
222-
portNum < this->getNum_productSendOut_OutputPorts(),
222+
(0 <= portNum) && (portNum < this->getNum_productSendOut_OutputPorts()),
223223
static_cast<FwAssertArgType>(portNum)
224224
);
225225

@@ -279,7 +279,7 @@ bool ActiveAsyncProductPortsOnlyComponentBase ::
279279
isConnected_productRequestOut_OutputPort(FwIndexType portNum)
280280
{
281281
FW_ASSERT(
282-
portNum < this->getNum_productRequestOut_OutputPorts(),
282+
(0 <= portNum) && (portNum < this->getNum_productRequestOut_OutputPorts()),
283283
static_cast<FwAssertArgType>(portNum)
284284
);
285285

@@ -290,7 +290,7 @@ bool ActiveAsyncProductPortsOnlyComponentBase ::
290290
isConnected_productSendOut_OutputPort(FwIndexType portNum)
291291
{
292292
FW_ASSERT(
293-
portNum < this->getNum_productSendOut_OutputPorts(),
293+
(0 <= portNum) && (portNum < this->getNum_productSendOut_OutputPorts()),
294294
static_cast<FwAssertArgType>(portNum)
295295
);
296296

@@ -313,7 +313,7 @@ void ActiveAsyncProductPortsOnlyComponentBase ::
313313
{
314314
// Make sure port number is valid
315315
FW_ASSERT(
316-
portNum < this->getNum_productRecvIn_InputPorts(),
316+
(0 <= portNum) && (portNum < this->getNum_productRecvIn_InputPorts()),
317317
static_cast<FwAssertArgType>(portNum)
318318
);
319319

@@ -405,7 +405,7 @@ void ActiveAsyncProductPortsOnlyComponentBase ::
405405
)
406406
{
407407
FW_ASSERT(
408-
portNum < this->getNum_productRequestOut_OutputPorts(),
408+
(0 <= portNum) && (portNum < this->getNum_productRequestOut_OutputPorts()),
409409
static_cast<FwAssertArgType>(portNum)
410410
);
411411

@@ -427,7 +427,7 @@ void ActiveAsyncProductPortsOnlyComponentBase ::
427427
)
428428
{
429429
FW_ASSERT(
430-
portNum < this->getNum_productSendOut_OutputPorts(),
430+
(0 <= portNum) && (portNum < this->getNum_productSendOut_OutputPorts()),
431431
static_cast<FwAssertArgType>(portNum)
432432
);
433433

0 commit comments

Comments
 (0)