Bug 2562 - lte-spectrum-value-helper.cc dead assignment
lte-spectrum-value-helper.cc dead assignment
Status: RESOLVED FIXED
Product: ns-3
Classification: Unclassified
Component: lte
pre-release
PC Linux
: P5 normal
Assigned To: Biljana Bojović
:
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2016-11-23 11:37 UTC by natale.patriciello
Modified: 2018-02-25 05:46 UTC (History)
2 users (show)

See Also:


Attachments
Patch (1.36 KB, patch)
2016-11-24 04:42 UTC, natale.patriciello
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description natale.patriciello 2016-11-23 11:37:49 UTC
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 ?
Comment 1 Biljana Bojović 2016-11-23 11:58:28 UTC
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?
Comment 2 natale.patriciello 2016-11-24 04:42:54 UTC
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 ?
Comment 3 Biljana Bojović 2016-11-24 04:53:39 UTC
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.
Comment 4 natale.patriciello 2018-02-25 05:46:44 UTC
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)