Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Backport release/3.6] Add missing #include <algorithm> for std::min/std::max uses, and #include <limits> for std::numeric_limits<> #6629

Merged
merged 1 commit into from Nov 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/workflows/code_checks.yml
Expand Up @@ -60,6 +60,9 @@ jobs:
- name: Detect suspicious char digit zero
run: ./scripts/detect_suspicious_char_digit_zero.sh

- name: Detect missing includes
run: ./scripts/detect_missing_include.sh

- name: Shellcheck
run: shellcheck -e SC2086,SC2046,SC2164,SC2054 $(find . -name '*.sh' -a -not -name ltmain.sh -a -not -wholename "./autotest/*" -a -not -wholename "./.github/*")

Expand Down
1 change: 1 addition & 0 deletions alg/gdal_rpc.cpp
Expand Up @@ -36,6 +36,7 @@
#include <cstring>

#include <algorithm>
#include <limits>
#include <string>

#include "cpl_conv.h"
Expand Down
1 change: 1 addition & 0 deletions alg/gdalrasterize.cpp
Expand Up @@ -36,6 +36,7 @@
#include <cstdlib>
#include <cstring>
#include <cfloat>
#include <limits>
#include <vector>
#include <algorithm>

Expand Down
1 change: 1 addition & 0 deletions alg/gdaltransformer.cpp
Expand Up @@ -41,6 +41,7 @@
#include <cstring>

#include <algorithm>
#include <limits>
#include <utility>

#include "cpl_conv.h"
Expand Down
69 changes: 35 additions & 34 deletions alg/marching_squares/square.h
Expand Up @@ -28,6 +28,7 @@
#ifndef MARCHING_SQUARE_SQUARE_H
#define MARCHING_SQUARE_SQUARE_H

#include <algorithm>
#include <cassert>
#include <cstdint>
#include <math.h>
Expand All @@ -39,15 +40,15 @@ namespace marching_squares {
struct Square
{
// Bit flags to determine borders around pixel
static const uint8_t NO_BORDER = 0; // 0000 0000
static const uint8_t LEFT_BORDER = 1 << 0; // 0000 0001
static const uint8_t NO_BORDER = 0; // 0000 0000
static const uint8_t LEFT_BORDER = 1 << 0; // 0000 0001
static const uint8_t LOWER_BORDER = 1 << 1; // 0000 0010
static const uint8_t RIGHT_BORDER = 1 << 2; // 0000 0100
static const uint8_t UPPER_BORDER = 1 << 3; // 0000 1000

// Bit flags for marching square case
static const uint8_t ALL_LOW = 0; // 0000 0000
static const uint8_t UPPER_LEFT = 1 << 0; // 0000 0001
static const uint8_t ALL_LOW = 0; // 0000 0000
static const uint8_t UPPER_LEFT = 1 << 0; // 0000 0001
static const uint8_t LOWER_LEFT = 1 << 1; // 0000 0010
static const uint8_t LOWER_RIGHT = 1 << 2; // 0000 0100
static const uint8_t UPPER_RIGHT = 1 << 3; // 0000 1000
Expand Down Expand Up @@ -107,27 +108,27 @@ struct Square
assert(lowerLeft.y == lowerRight.y);
assert(lowerLeft.x == upperLeft.x);
assert(lowerRight.x == upperRight.x);
assert(!split || nanCount == 0);
assert(!split || nanCount == 0);
}

Square upperLeftSquare() const
{
Square upperLeftSquare() const
{
assert(!std::isnan(upperLeft.value));
return Square(
upperLeft, upperCenter(),
upperLeft, upperCenter(),
leftCenter(), center(),
(std::isnan(upperRight.value) ? RIGHT_BORDER: NO_BORDER)
| (std::isnan(lowerLeft.value) ? LOWER_BORDER : NO_BORDER), true);
(std::isnan(upperRight.value) ? RIGHT_BORDER: NO_BORDER)
| (std::isnan(lowerLeft.value) ? LOWER_BORDER : NO_BORDER), true);
}

Square lowerLeftSquare() const
{
{
assert(!std::isnan(lowerLeft.value));
return Square(
leftCenter(), center(),
leftCenter(), center(),
lowerLeft, lowerCenter(),
(std::isnan(lowerRight.value) ? RIGHT_BORDER: NO_BORDER)
| (std::isnan(upperLeft.value) ? UPPER_BORDER : NO_BORDER), true);
(std::isnan(lowerRight.value) ? RIGHT_BORDER: NO_BORDER)
| (std::isnan(upperLeft.value) ? UPPER_BORDER : NO_BORDER), true);
}

Square lowerRightSquare() const
Expand All @@ -137,7 +138,7 @@ struct Square
center(), rightCenter(),
lowerCenter(), lowerRight,
(std::isnan(lowerLeft.value) ? LEFT_BORDER: NO_BORDER)
| (std::isnan(upperRight.value) ? UPPER_BORDER : NO_BORDER), true);
| (std::isnan(upperRight.value) ? UPPER_BORDER : NO_BORDER), true);
}

Square upperRightSquare() const
Expand All @@ -147,20 +148,20 @@ struct Square
upperCenter(), upperRight,
center(), rightCenter(),
(std::isnan(lowerRight.value) ? LOWER_BORDER: NO_BORDER)
| (std::isnan(upperLeft.value) ? LEFT_BORDER : NO_BORDER), true);
}
| (std::isnan(upperLeft.value) ? LEFT_BORDER : NO_BORDER), true);
}

double maxValue() const
{
assert(nanCount==0);
return std::max(std::max(upperLeft.value, upperRight.value),
return std::max(std::max(upperLeft.value, upperRight.value),
std::max(lowerLeft.value, lowerRight.value));
}

double minValue() const
{
assert(nanCount==0);
return std::min(std::min(upperLeft.value, upperRight.value),
return std::min(std::min(upperLeft.value, upperRight.value),
std::min(lowerLeft.value, lowerRight.value));
}

Expand Down Expand Up @@ -277,7 +278,7 @@ struct Square
// bitwise AND to test which borders we have on the square
if ( ( border & borders ) == 0 )
continue;

// convention: for a level = L, store borders for the previous level up to
// (and including) L in the border of level "L".
// For fixed sets of level, this means there is an "Inf" slot for borders of the highest level
Expand Down Expand Up @@ -353,7 +354,7 @@ struct Square

ValuedPoint center() const
{
return ValuedPoint(
return ValuedPoint(
.5*(upperLeft.x + lowerRight.x),
.5*(upperLeft.y + lowerRight.y),
( (std::isnan(lowerLeft.value) ? 0 : lowerLeft.value)
Expand All @@ -365,39 +366,39 @@ struct Square

ValuedPoint leftCenter() const
{
return ValuedPoint(
return ValuedPoint(
upperLeft.x,
.5*(upperLeft.y + lowerLeft.y),
.5*(upperLeft.y + lowerLeft.y),
std::isnan(upperLeft.value)
? lowerLeft.value
: (std::isnan(lowerLeft.value) ? upperLeft.value : .5*(upperLeft.value + lowerLeft.value)));
}

ValuedPoint lowerCenter() const
{
return ValuedPoint(
return ValuedPoint(
.5*(lowerLeft.x + lowerRight.x),
lowerLeft.y,
lowerLeft.y,
std::isnan(lowerRight.value)
? lowerLeft.value
: (std::isnan(lowerLeft.value) ? lowerRight.value : .5*(lowerRight.value + lowerLeft.value)));
}

ValuedPoint rightCenter() const
{
return ValuedPoint(
return ValuedPoint(
upperRight.x,
.5*(upperRight.y + lowerRight.y),
.5*(upperRight.y + lowerRight.y),
std::isnan(lowerRight.value)
? upperRight.value
: (std::isnan(upperRight.value) ? lowerRight.value : .5*(lowerRight.value + upperRight.value)));
}

ValuedPoint upperCenter() const
{
return ValuedPoint(
return ValuedPoint(
.5*(upperLeft.x + upperRight.x),
upperLeft.y,
upperLeft.y,
std::isnan(upperLeft.value)
? upperRight.value
: (std::isnan(upperRight.value) ? upperLeft.value : .5*(upperLeft.value + upperRight.value)));
Expand Down Expand Up @@ -446,16 +447,16 @@ struct Square
switch (border)
{
case LEFT_BORDER:
return Point(upperLeft.x, interpolate_(level, lowerLeft.y, upperLeft.y,
return Point(upperLeft.x, interpolate_(level, lowerLeft.y, upperLeft.y,
lowerLeft.value, upperLeft.value, !split));
case LOWER_BORDER:
return Point(interpolate_(level, lowerLeft.x, lowerRight.x,
return Point(interpolate_(level, lowerLeft.x, lowerRight.x,
lowerLeft.value, lowerRight.value, !split), lowerLeft.y);
case RIGHT_BORDER:
return Point(upperRight.x, interpolate_(level, lowerRight.y, upperRight.y,
return Point(upperRight.x, interpolate_(level, lowerRight.y, upperRight.y,
lowerRight.value, upperRight.value, !split));
case UPPER_BORDER:
return Point(interpolate_(level, upperLeft.x, upperRight.x,
return Point(interpolate_(level, upperLeft.x, upperRight.x,
upperLeft.value, upperRight.value, !split), upperLeft.y);
}
assert(false);
Expand Down
1 change: 1 addition & 0 deletions apps/gdalinfo_lib.cpp
Expand Up @@ -33,6 +33,7 @@
#include "gdal_utils_priv.h"

#include <cmath>
#include <limits>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
Expand Down
1 change: 1 addition & 0 deletions autotest/cpp/test_cpl.cpp
Expand Up @@ -57,6 +57,7 @@
#include "cpl_threadsafe_queue.hpp"

#include <atomic>
#include <limits>
#include <fstream>
#include <string>

Expand Down
1 change: 1 addition & 0 deletions frmts/adrg/srpdataset.cpp
Expand Up @@ -35,6 +35,7 @@

#include <cstdlib>
#include <algorithm>
#include <limits>

// Uncomment to recognize also .gen files in addition to .img files
// #define OPEN_GEN
Expand Down
1 change: 1 addition & 0 deletions frmts/basisu_ktx2/common.cpp
Expand Up @@ -30,6 +30,7 @@
#include "common.h"
#include "include_basisu_sdk.h"

#include <algorithm>
#include <mutex>

/************************************************************************/
Expand Down
1 change: 1 addition & 0 deletions frmts/exr/exrdataset.cpp
Expand Up @@ -29,6 +29,7 @@
#include "ogr_spatialref.h"

#include <algorithm>
#include <limits>
#include <mutex>

#include "openexr_headers.h"
Expand Down
2 changes: 1 addition & 1 deletion frmts/fit/fitdataset.cpp
Expand Up @@ -35,7 +35,7 @@
#include "cpl_safemaths.hpp"

#include <algorithm>

#include <limits>

constexpr size_t FIT_PAGE_SIZE = 128;

Expand Down
1 change: 1 addition & 0 deletions frmts/grib/gribcreatecopy.cpp
Expand Up @@ -36,6 +36,7 @@
#include "gdal_priv_templates.hpp"
#include "memdataset.h"

#include <algorithm>
#include <limits>

#include "degrib/degrib/meta.h"
Expand Down
1 change: 1 addition & 0 deletions frmts/gtiff/geotiff.cpp
Expand Up @@ -48,6 +48,7 @@
#endif

#include <algorithm>
#include <limits>
#include <map>
#include <memory>
#include <mutex>
Expand Down
1 change: 1 addition & 0 deletions frmts/hfa/hfadataset.cpp
Expand Up @@ -43,6 +43,7 @@
# include <fcntl.h>
#endif
#include <algorithm>
#include <limits>
#include <memory>
#include <string>
#include <vector>
Expand Down
1 change: 1 addition & 0 deletions frmts/jpeg/jpgdataset.cpp
Expand Up @@ -43,6 +43,7 @@
#if HAVE_FCNTL_H
# include <fcntl.h>
#endif
#include <limits>
#include <setjmp.h>

#include <algorithm>
Expand Down
1 change: 1 addition & 0 deletions frmts/pdf/pdfcreatefromcomposition.cpp
Expand Up @@ -30,6 +30,7 @@
#include "gdal_pdf.h"
#include "pdfcreatecopy.h"

#include <algorithm>
#include <cmath>
#include <cstdlib>

Expand Down
2 changes: 1 addition & 1 deletion frmts/raw/byndataset.cpp
Expand Up @@ -37,7 +37,7 @@
#include "ogr_srs_api.h"

#include <cstdlib>

#include <limits>

// Specification at
// https://www.nrcan.gc.ca/sites/www.nrcan.gc.ca/files/earthsciences/pdf/gpshgrid_e.pdf
Expand Down
2 changes: 2 additions & 0 deletions frmts/rdb/rdbdataset.cpp
Expand Up @@ -31,6 +31,8 @@

#include "rdbdataset.hpp"

#include <algorithm>
#include <limits>
#include <cmath>
#include <sstream>

Expand Down
3 changes: 2 additions & 1 deletion frmts/rdb/rdbdataset.hpp
Expand Up @@ -36,6 +36,7 @@
#include <riegl/rdb.hpp>

#include <algorithm>
#include <limits>
#include <memory>
#include <mutex>
#include <string>
Expand Down Expand Up @@ -147,4 +148,4 @@ class RDBRasterBand CPL_NON_FINAL: public GDALPamRasterBand
} // namespace rdb
void GDALRegister_RDB();

#endif // RDB_DATASET_INCLUDED
#endif // RDB_DATASET_INCLUDED
1 change: 1 addition & 0 deletions frmts/rmf/rmfdataset.cpp
Expand Up @@ -27,6 +27,7 @@
* DEALINGS IN THE SOFTWARE.
****************************************************************************/
#include <algorithm>
#include <limits>

#include "cpl_string.h"
#include "gdal_frmts.h"
Expand Down
1 change: 1 addition & 0 deletions frmts/rmf/rmfdem.cpp
Expand Up @@ -31,6 +31,7 @@

#include "rmfdataset.h"

#include <limits>

/*
* The encoded data stream is a series of records.
Expand Down
2 changes: 1 addition & 1 deletion frmts/sigdem/sigdemdataset.cpp
Expand Up @@ -30,7 +30,7 @@
#include "rawdataset.h"

#include <algorithm>

#include <limits>

#ifdef CPL_IS_LSB
#define SWAP_SIGDEM_HEADER(abyHeader) { \
Expand Down
1 change: 1 addition & 0 deletions frmts/wms/gdalwmsrasterband.cpp
Expand Up @@ -31,6 +31,7 @@

#include "wmsdriver.h"

#include <algorithm>

GDALWMSRasterBand::GDALWMSRasterBand(GDALWMSDataset *parent_dataset, int band,
double scale):
Expand Down
1 change: 1 addition & 0 deletions gcore/gdalmultidim.cpp
Expand Up @@ -30,6 +30,7 @@

#include <assert.h>
#include <algorithm>
#include <limits>
#include <queue>
#include <set>

Expand Down
1 change: 1 addition & 0 deletions gcore/tilematrixset.cpp
Expand Up @@ -31,6 +31,7 @@

#include <cmath>
#include <cfloat>
#include <limits>

#include "tilematrixset.hpp"

Expand Down