<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
Michael,<br>
<br>
oh, the dreadful c_str() trap once again… nice find.<br>
<br>
The deallocated heap buffer *can* have been reallocated easily,
we're running on a preemptive OS and on two CPU cores.<br>
<br>
IOW, all of these need to be fixed. Sure there are only 8 of them?<br>
<br>
On your is_empty_metric() utility: may be I miss something, but why
don't we simply use the metric's IsDefined() method?<br>
<br>
Regards,<br>
Michael<br>
<br>
<br>
<div class="moz-cite-prefix">Am 02.10.22 um 13:37 schrieb Michael
Geddes:<br>
</div>
<blockquote type="cite"
cite="mid:CAH0p7uLURoKhXa1ySH3Ox3oAL8mfFfE_Gq5-0iNDRRMjwTrPSw@mail.gmail.com">
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<div dir="auto">
<div dir="ltr">Hi all,
<div><br>
</div>
<div>I noticed some behavior on the <b>tpms</b> command I'd
copied from the Kia/Kona code, which sent me down a small
rabbit hole.</div>
<div>What I was seeing was that the temperature was repeated
instead of seeing the pressure and temperature.</div>
<div><br>
</div>
<div>Even in vehicle.cpp, we can see code like this:</div>
<div dir="auto"><br>
</div>
<div> <font face="monospace">const char* range_est =
StdMetrics.ms_v_bat_range_est->AsUnitString("-",
rangeUnit, 0).c_str();<br>
if (*range_est != '-')<br>
writer->printf("Est. range: %s\n", range_est);</font></div>
<div dir="auto"><font face="monospace"><br>
</font></div>
<div>My C++ is a bit rusty, however I believe that the 'const
char*' won't hold the temporary std::string object returned
by 'AsUnitString'. To do that, I believe we need to assign
to a reference (which I know will work). The problem is
that the original code will mostly work (especially in cases
like the above), as the deallocated heap memory won't have
been reallocated.</div>
<div><br>
<font face="monospace"> const std::string& range_est =
StdMetrics.ms_v_bat_range_est->AsUnitString("-",
rangeUnit, 0);<br>
if (!is_empty_metric(range_est))<br>
writer->printf("Est. range: %s\n",
range_est.c_str());<br>
</font></div>
<div><br>
</div>
<div>Where I've defined in vehicle.h the following:</div>
<div><font face="monospace">inline bool is_empty_metric(const
std::string &measure)<br>
{<br>
return (measure == "") || (measure[0] == '-');<br>
}<br>
</font><br>
</div>
<div>Will the above work functionally? Would it be better to
be: </div>
<div dir="auto"><br>
</div>
<div dir="auto">return (measure =="") || (measure == "-") </div>
<div dir="auto"><br>
</div>
<div>This occurs in 8 files (outside my new Ioniq 5 files)
that I have noted. </div>
<div dir="auto"><br>
</div>
<div>I would make a separate commit for this and do a pull
request for it, </div>
<div><br>
</div>
<div>//.ichael</div>
<div><br>
</div>
</div>
</div>
<br>
<fieldset class="moz-mime-attachment-header"></fieldset>
<pre class="moz-quote-pre" wrap="">_______________________________________________
OvmsDev mailing list
<a class="moz-txt-link-abbreviated" href="mailto:OvmsDev@lists.openvehicles.com">OvmsDev@lists.openvehicles.com</a>
<a class="moz-txt-link-freetext" href="http://lists.openvehicles.com/mailman/listinfo/ovmsdev">http://lists.openvehicles.com/mailman/listinfo/ovmsdev</a>
</pre>
</blockquote>
<br>
<pre class="moz-signature" cols="72">--
Michael Balzer * Helkenberger Weg 9 * D-58256 Ennepetal
Fon 02333 / 833 5735 * Handy 0176 / 206 989 26</pre>
</body>
</html>