Skip to content

Commit 34b01a2

Browse files
committed
Don't use std::forward in a loop
This could be a use after move.
1 parent 7ab133e commit 34b01a2

File tree

3 files changed

+10
-11
lines changed

3 files changed

+10
-11
lines changed

src/geom-functions.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,13 @@ point_t interpolate(point_t p1, point_t p2, double frac) noexcept;
4343
* \pre \code !list.empty() \endcode
4444
*/
4545
template <typename FUNC>
46-
void for_each_segment(point_list_t const &list, FUNC &&func)
46+
void for_each_segment(point_list_t const &list, FUNC const &func)
4747
{
4848
assert(!list.empty());
4949
auto it = list.cbegin();
5050
auto prev = it;
5151
for (++it; it != list.cend(); ++it) {
52-
std::forward<FUNC>(func)(*prev, *it);
52+
func(*prev, *it);
5353
prev = it;
5454
}
5555
}

src/lua-utils.hpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,14 +40,14 @@ void luaX_add_table_func(lua_State *lua_state, char const *key,
4040

4141
template <typename COLLECTION, typename FUNC>
4242
void luaX_add_table_array(lua_State *lua_state, char const *key,
43-
COLLECTION const &collection, FUNC &&func)
43+
COLLECTION const &collection, FUNC const &func)
4444
{
4545
lua_pushstring(lua_state, key);
4646
lua_createtable(lua_state, (int)collection.size(), 0);
4747
int n = 0;
4848
for (auto const &member : collection) {
4949
lua_pushinteger(lua_state, ++n);
50-
std::forward<FUNC>(func)(member);
50+
func(member);
5151
lua_rawset(lua_state, -3);
5252
}
5353
lua_rawset(lua_state, -3);
@@ -99,15 +99,15 @@ bool luaX_is_array(lua_State *lua_state);
9999
* \post Stack is unchanged.
100100
*/
101101
template <typename FUNC>
102-
void luaX_for_each(lua_State *lua_state, FUNC &&func)
102+
void luaX_for_each(lua_State *lua_state, FUNC const &func)
103103
{
104104
assert(lua_istable(lua_state, -1));
105105
lua_pushnil(lua_state);
106106
while (lua_next(lua_state, -2) != 0) {
107107
#ifndef NDEBUG
108108
int const top = lua_gettop(lua_state);
109109
#endif
110-
std::forward<FUNC>(func)();
110+
func();
111111
assert(top == lua_gettop(lua_state));
112112
lua_pop(lua_state, 1);
113113
}

src/tile.hpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -281,14 +281,14 @@ class tile_t
281281
*/
282282
template <class OUTPUT>
283283
std::size_t for_each_tile(quadkey_list_t const &tiles_at_maxzoom,
284-
uint32_t minzoom, uint32_t maxzoom, OUTPUT &&output)
284+
uint32_t minzoom, uint32_t maxzoom,
285+
OUTPUT const &output)
285286
{
286287
assert(minzoom <= maxzoom);
287288

288289
if (minzoom == maxzoom) {
289290
for (auto const quadkey : tiles_at_maxzoom) {
290-
std::forward<OUTPUT>(output)(
291-
tile_t::from_quadkey(quadkey, maxzoom));
291+
output(tile_t::from_quadkey(quadkey, maxzoom));
292292
}
293293
return tiles_at_maxzoom.size();
294294
}
@@ -309,8 +309,7 @@ std::size_t for_each_tile(quadkey_list_t const &tiles_at_maxzoom,
309309
* the first sibling.
310310
*/
311311
if (qt_current != last_quadkey.down(dz)) {
312-
std::forward<OUTPUT>(output)(
313-
tile_t::from_quadkey(qt_current, maxzoom - dz));
312+
output(tile_t::from_quadkey(qt_current, maxzoom - dz));
314313
++count;
315314
}
316315
}

0 commit comments

Comments
 (0)