|
Bugzilla – Full Text Bug Listing |
| Summary: | lte-spectrum-value-helper.cc dead assignment | ||
|---|---|---|---|
| Product: | ns-3 | Reporter: | natale.patriciello |
| Component: | lte | Assignee: | Biljana Bojović <bbojovic> |
| Status: | RESOLVED FIXED | ||
| Severity: | normal | CC: | ns-bugs, tomh |
| Priority: | P5 | ||
| Version: | pre-release | ||
| Hardware: | PC | ||
| OS: | Linux | ||
| Attachments: | Patch | ||
Thanks for reporting. It seems to me that we can move the declaration of powerTxW to line 275, as it seems to be necessary only in that block. And in line 270 could be used basicPowerTxW instead of powerTxW as they have the same initial value. Sounds ok? Created attachment 2682 [details]
Patch
I tried to do the patch, and now the static analyzer does not complain anymore. Is the functionality now on the patch the intended operation ?
To me, this looks functionally equivalent to the original version. Maybe we do not need the declaration of basicTxPowerDensity. But I would leave that to your choice. For me is ok this patch. Already fixed in commit Tue Mar 7 14:33:39 2017 +0100 1cd0010e1 lte: fix static code analysys warnings (thanks to Natale Patriciello) [Biljana Bojovic] (from git log) |
This dead assignment is more dangerous than the others. The method is this (lte-spectrum-value-helper.cc:258) 258 Ptr<SpectrumValue> 259 LteSpectrumValueHelper::CreateTxPowerSpectralDensity (uint16_t earfcn, uint8_t txBandwidthConfiguration, double powerTx, std::map<int, double> powerTxMap, std::vector <int> activeRbs) 260 { 261 NS_LOG_FUNCTION (earfcn << (uint16_t) txBandwidthConfiguration << activeRbs); 262 263 Ptr<SpectrumModel> model = GetSpectrumModel (earfcn, txBandwidthConfiguration); 264 Ptr<SpectrumValue> txPsd = Create <SpectrumValue> (model); 265 266 // powerTx is expressed in dBm. We must convert it into natural unit. 267 double powerTxW = std::pow (10., (powerTx - 30) / 10); 268 double basicPowerTxW = std::pow (10., (powerTx - 30) / 10); 269 270 double txPowerDensity = (powerTxW / (txBandwidthConfiguration * 180000)); // Value stored to 'txPowerDensity' during its initialization is never read 271 272 for (std::vector <int>::iterator it = activeRbs.begin (); it != activeRbs.end (); it++) 273 { 274 int rbId = (*it); 275 276 std::map<int, double>::iterator powerIt = powerTxMap.find (rbId); 277 278 if (powerIt != powerTxMap.end ()) 279 { 280 powerTxW = std::pow (10., (powerIt->second - 30) / 10); 281 txPowerDensity = (powerTxW / (txBandwidthConfiguration * 180000)); 282 } 283 else 284 { 285 txPowerDensity = (basicPowerTxW / (txBandwidthConfiguration * 180000)); 286 } 287 288 (*txPsd)[rbId] = txPowerDensity; 289 } 290 291 NS_LOG_LOGIC (*txPsd); 292 293 return txPsd; 294 } At line 270, the inizialization made is never read (because it is overwritten at line 281). But, the dangerous thing is that if we empty that assignment, then the line 267 becomes a dead assignment (because the value powerTxW is overwritten at line 280). But then, if we remove that initialization, the parameter "powerTx" is never read. It means that, currently, the parameter "powerTx" is ignored. How we can fix this ?