[PATCH] Refactoring based on cppcheck suggestions

Richard Kimberly Heck rikiheck at lyx.org
Sun Oct 4 17:10:05 UTC 2020


On 10/4/20 12:27 PM, Yuriy Skalko wrote:
>> Thanks, it is in.
>>
>> JMarc
> Continuing with refactoring LyX code.

This all looks fine, except for this one:

diff --git a/src/insets/InsetTabular.cpp b/src/insets/InsetTabular.cpp
index 8458ce4728..fdfef40556 100644
--- a/src/insets/InsetTabular.cpp
+++ b/src/insets/InsetTabular.cpp
@@ -2189,9 +2189,7 @@ bool Tabular::needRotating() const
 
 bool Tabular::isLastCell(idx_type cell) const
 {
-    if (cell + 1 < numberofcells)
-        return false;
-    return true;
+    return cell >= numberofcells - 1;
 }

What happens if size_t numberofcells is 0 and cell is also 0? What is 0
- 1 for an unsigned int? Maybe numberofcells can't be 0, but still it
seems a bit confusing. I'd suggest:

    return cell + 1 >= numberofcells;

instead.

Riki




More information about the lyx-devel mailing list