Home » U++ Library support » U++ Core » clamp() function crashes apps on Linux, gets warning from GCC and CLANG
clamp() function crashes apps on Linux, gets warning from GCC and CLANG [message #54576] |
Sat, 15 August 2020 23:10 |
Oblivion
Messages: 1093 Registered: August 2007
|
Senior Contributor |
|
|
Hi,
clamp function in the latest SVN build (rev. 14827) crashes apps.
GCC and CLANG complains about a reference to local variable addr.
Example:
#include <Core/Core.h>
using namespace Upp;
Size fn1()
{
Size sz1(Random(100), Random(100));
Size sz2(Random(1000), Random(1000));
Size sz3(Random(1000), Random(1000));
return clamp(sz1, sz2, sz3);
}
Size fn2()
{
Size sz1(Random(100), Random(100));
Size sz2(Random(1000), Random(1000));
Size sz3(Random(1000), Random(1000));
return min(max(sz1, sz2), sz3);
}
CONSOLE_APP_MAIN
{
// both GCC and CLANG warns about reference to local-addr.
Size sz1 = fn1(); // Crashes the app with invalid memory access.
DUMP(sz1);
Size sz2 = fn2(); // Does not crash.
DUMP(sz2);
}
Best regards,
Oblivion
Github page: https://github.com/ismail-yilmaz
upp-components: https://github.com/ismail-yilmaz/upp-components
Bobcat the terminal emulator: https://github.com/ismail-yilmaz/Bobcat
[Updated on: Sat, 15 August 2020 23:29] Report message to a moderator
|
|
|
Re: clamp() function crashes apps on Linux, gets warning from GCC and CLANG [message #54577 is a reply to message #54576] |
Sun, 16 August 2020 12:27 |
|
mirek
Messages: 13976 Registered: November 2005
|
Ultimate Member |
|
|
Oblivion wrote on Sat, 15 August 2020 23:10Hi,
clamp function in the latest SVN build (rev. 14827) crashes apps.
GCC and CLANG complains about a reference to local variable addr.
Example:
#include <Core/Core.h>
using namespace Upp;
Size fn1()
{
Size sz1(Random(100), Random(100));
Size sz2(Random(1000), Random(1000));
Size sz3(Random(1000), Random(1000));
return clamp(sz1, sz2, sz3);
}
Size fn2()
{
Size sz1(Random(100), Random(100));
Size sz2(Random(1000), Random(1000));
Size sz3(Random(1000), Random(1000));
return min(max(sz1, sz2), sz3);
}
CONSOLE_APP_MAIN
{
// both GCC and CLANG warns about reference to local-addr.
Size sz1 = fn1(); // Crashes the app with invalid memory access.
DUMP(sz1);
Size sz2 = fn2(); // Does not crash.
DUMP(sz2);
}
Best regards,
Oblivion
Interesting one. The real reason is that it goes to overloaded min/max.
For now fixed by changing singnature
template <class T>
constexpr T clamp(const T& x, const T& min_, const T& max_)
Hopefully this will not explode anywhere else...
Mirek
|
|
|
Goto Forum:
Current Time: Sat May 11 15:58:59 CEST 2024
Total time taken to generate the page: 0.02970 seconds
|