Avoid 'conversion may change value' cases related to Synchronizer and Lister
Avoid two 'conversion may change value' warnings in synchronizertask.cpp, confirming a conversion to int
because ─as it's stated in the documentation─ "qint64 QIODevice::read(char *data, qint64 maxSize)
Reads at most maxSize
bytes" and maxSize
is only 1440 in this case.
Avoid a 'conversion may change value' warning in synchronizer.cpp, using a time_t
data type instead of an int
.
Avoid four 'conversion may change value' warnings in synchronizer.cpp, confirming conversions to uint
because a non-Krusader function that is used (fromTime_t()
) does not accept data types that are bigger than uint
.
Avoid several 'conversion from long long int
to int
may change value' warnings in lister.cpp, confirming conversions to int
because some non-Krusader functions that are used (like setPageStep(int)
, setMaximum(int)
, left(int)
, mid(int index, int len = -1)
or lastIndexOf(const QString &s, int from)
) do not accept data types that are bigger than int
.
Avoid some 'conversion may change value' warnings (like "from double
to float
") in lister.cpp by means of using a double
variable instead of a float
one and confirming a conversion to int
because after it the number is only used as an integer.
Avoid several 'conversion from long long int
to int
may change value' warnings in lister.cpp by means of using qint64
variables instead of int
ones. Note: qint64
is the chosen type because it is what some functions return.
The warnings are:
/home/user/krusader/krusader/Synchronizer/synchronizertask.cpp:175:39: warning: conversion from ‘qint64’ {aka ‘long long int’} to ‘int’ may change value [-Wconversion]
175 | int leftBytes = leftFile->read(leftBuffer, sizeof(leftBuffer));
| ~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/home/user/krusader/krusader/Synchronizer/synchronizertask.cpp:176:41: warning: conversion from ‘qint64’ {aka ‘long long int’} to ‘int’ may change value [-Wconversion]
176 | int rightBytes = rightFile->read(rightBuffer, sizeof(rightBuffer));
| ~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/home/user/krusader/krusader/Synchronizer/synchronizer.cpp:450:38: warning: conversion from ‘time_t’ {aka ‘long int’} to ‘int’ may change value [-Wconversion]
450 | int checkedRightDate = rightDate - timeOffset;
| ~~~~~~~~~~^~~~~~~~~~~~
/home/user/krusader/krusader/Synchronizer/synchronizer.cpp:1114:93: warning: conversion from ‘time_t’ {aka ‘long int’} to ‘uint’ {aka ‘unsigned int’} may change value [-Wconversion]
1114 | QDateTime(), QDateTime::fromTime_t(item->rightDate()),
| ~~~~~~~~~~~~~~~^~
/home/user/krusader/krusader/Synchronizer/synchronizer.cpp:1115:79: warning: conversion from ‘time_t’ {aka ‘long int’} to ‘uint’ {aka ‘unsigned int’} may change value [-Wconversion]
1115 | QDateTime::fromTime_t(item->leftDate()));
| ~~~~~~~~~~~~~~^~
/home/user/krusader/krusader/Synchronizer/synchronizer.cpp:1122:92: warning: conversion from ‘time_t’ {aka ‘long int’} to ‘uint’ {aka ‘unsigned int’} may change value [-Wconversion]
1122 | QDateTime(), QDateTime::fromTime_t(item->leftDate()),
| ~~~~~~~~~~~~~~^~
/home/user/krusader/krusader/Synchronizer/synchronizer.cpp:1123:80: warning: conversion from ‘time_t’ {aka ‘long int’} to ‘uint’ {aka ‘unsigned int’} may change value [-Wconversion]
1123 | QDateTime::fromTime_t(item->rightDate()));
| ~~~~~~~~~~~~~~~^~
/home/user/krusader/krusader/KViewer/lister.cpp:118:186: warning: conversion from ‘double’ to ‘float’ may change value [-Wfloat-conversion]
118 | const float fontWidth = (fm.QFONTMETRICS_WIDTH("WWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWW") - fm.QFONTMETRICS_WIDTH("W")) / 99.0;
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~
/home/user/krusader/krusader/KViewer/lister.cpp:125:39: warning: conversion from ‘int’ to ‘float’ may change value [-Wconversion]
125 | SET_TAB_STOP_DISTANCE(fontWidth * _tabWidth);
| ^~~~~~~~~
/home/user/krusader/krusader/KViewer/../compat.h:128:57: note: in definition of macro ‘SET_TAB_STOP_DISTANCE’
128 | #define SET_TAB_STOP_DISTANCE(X) setTabStopDistance(X)
| ^
/home/user/krusader/krusader/KViewer/lister.cpp:127:23: warning: conversion from ‘int’ to ‘float’ may change value [-Wconversion]
127 | const int sizeX = textViewportWidth / fontWidth;
| ^~~~~~~~~~~~~~~~~
/home/user/krusader/krusader/KViewer/lister.cpp:127:41: warning: conversion from ‘float’ to ‘int’ may change value [-Wfloat-conversion]
127 | const int sizeX = textViewportWidth / fontWidth;
| ~~~~~~~~~~~~~~~~~~^~~~~~~~~~~
/home/user/krusader/krusader/KViewer/lister.cpp:230:52: warning: conversion from ‘long long int’ to ‘int’ may change value [-Wconversion]
230 | QByteArray cachedBuffer = chunk.left(p - previousRow);
| ~~^~~~~~~~~~~~~
/home/user/krusader/krusader/KViewer/lister.cpp:244:50: warning: conversion from ‘long long int’ to ‘int’ may change value [-Wconversion]
244 | const QByteArray cachedBuffer = chunk.left(p - rowStart);
| ~~^~~~~~~~~~
/home/user/krusader/krusader/KViewer/lister.cpp:353:23: warning: conversion from ‘qint64’ {aka ‘long long int’} to ‘int’ may change value [-Wconversion]
353 | int anchPos = _cursorAnchorPos;
| ^~~~~~~~~~~~~~~~
/home/user/krusader/krusader/KViewer/lister.cpp:356:23: warning: conversion from ‘qint64’ {aka ‘long long int’} to ‘int’ may change value [-Wconversion]
356 | anchPos = _screenStartPos;
| ^~~~~~~~~~~~~~~
/home/user/krusader/krusader/KViewer/lister.cpp:361:23: warning: conversion from ‘qint64’ {aka ‘long long int’} to ‘int’ may change value [-Wconversion]
361 | anchPos = _screenEndPos;
| ^~~~~~~~~~~~~
/home/user/krusader/krusader/KViewer/lister.cpp:551:62: warning: conversion from ‘long long int’ to ‘int’ may change value [-Wconversion]
551 | const int maximum = (_lastPageStartPos > SLIDER_MAX) ? SLIDER_MAX : _lastPageStartPos;
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/home/user/krusader/krusader/KViewer/lister.cpp:552:57: warning: conversion from ‘qint64’ {aka ‘long long int’} to ‘int’ may change value [-Wconversion]
552 | int pageSize = (_lastPageStartPos > SLIDER_MAX) ? SLIDER_MAX * _averagePageSize / _lastPageStartPos : _averagePageSize;
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/home/user/krusader/krusader/KViewer/lister.cpp:807:35: warning: conversion from ‘qint64’ {aka ‘long long int’} to ‘int’ may change value [-Wconversion]
807 | maxSize = _screenStartPos - readPos;
| ~~~~~~~~~~~~~~~~^~~~~~~~~
/home/user/krusader/krusader/KViewer/lister.cpp:878:35: warning: conversion from ‘qint64’ {aka ‘long long int’} to ‘int’ may change value [-Wconversion]
878 | maxSize = _screenStartPos - readPos;
| ~~~~~~~~~~~~~~~~^~~~~~~~~
/home/user/krusader/krusader/KViewer/lister.cpp:985:56: warning: conversion from ‘qint64’ {aka ‘long long int’} to ‘int’ may change value [-Wconversion]
985 | const int value = (_lastPageStartPos > SLIDER_MAX) ? SLIDER_MAX * _screenStartPos / _lastPageStartPos : _screenStartPos;
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/home/user/krusader/krusader/KViewer/lister.cpp:1382:26: warning: conversion from ‘qint64’ {aka ‘long long int’} to ‘int’ may change value [-Wconversion]
1382 | size = _fileSize - filePos;
| ~~~~~~~~~~^~~~~~~~~
/home/user/krusader/krusader/KViewer/lister.cpp:1386:35: warning: conversion from ‘long long int’ to ‘int’ may change value [-Wconversion]
1386 | return _cache.mid(filePos - _cachePos, size);
| ~~~~~~~~^~~~~~~~~~~
/home/user/krusader/krusader/KViewer/lister.cpp:1411:32: warning: conversion from ‘long long int’ to ‘int’ may change value [-Wconversion]
1411 | int newSize = bytes.size() - cacheRefIndex;
| ~~~~~~~~~~~~~^~~~~~~~~~~~~~~
/home/user/krusader/krusader/KViewer/lister.cpp:1415:23: warning: conversion from ‘qint64’ {aka ‘long long int’} to ‘int’ may change value [-Wconversion]
1415 | return _cache.mid(cacheRefIndex, size);
| ^~~~~~~~~~~~~
/home/user/krusader/krusader/KViewer/lister.cpp:1605:28: warning: conversion from ‘qint64’ {aka ‘long long int’} to ‘int’ may change value [-Wconversion]
1605 | maxCacheSize = diff;
| ^~~~
/home/user/krusader/krusader/KViewer/lister.cpp:1627:47: warning: conversion from ‘qint64’ {aka ‘long long int’} to ‘int’ may change value [-Wconversion]
1627 | byteCounter = _searchPosition - searchPos;
| ~~~~~~~~~~~~~~~~^~~~~~~~~~~
TEST PLAN
Krusader should work correctly after applying the proposed changes. If anyone wants to perform some tests:
- Synchronize two folders with Synchronizer, using some date-related options like "Ignore Date". Check that the results are correct.
- See several types of documents with Lister, check that the size of characters is correct, increase and decrease the size with Ctrl++ and Ctrl--, press PgUp and PgDown, search for a letter that exists in several places of the file. Check that the results are correct.