Skip to content

Commit

Permalink
Enforcing IntelRealSense#2763 - fail examples if API has -Wshadow war…
Browse files Browse the repository at this point in the history
…nings
  • Loading branch information
dorodnic committed Nov 28, 2018
1 parent 6d16dfc commit 7dc02e2
Show file tree
Hide file tree
Showing 7 changed files with 61 additions and 59 deletions.
2 changes: 2 additions & 0 deletions examples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ set(CMAKE_EXPORT_COMPILE_COMMANDS 1)
# View the makefile commands during build
#set(CMAKE_VERBOSE_MAKEFILE on)

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror=shadow")

if(BUILD_GRAPHICAL_EXAMPLES)
include(${CMAKE_SOURCE_DIR}/CMake/opengl_config.cmake)
else()
Expand Down
16 changes: 8 additions & 8 deletions examples/example.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -234,27 +234,27 @@ class window
glfwMakeContextCurrent(win);

glfwSetWindowUserPointer(win, this);
glfwSetMouseButtonCallback(win, [](GLFWwindow * win, int button, int action, int mods)
glfwSetMouseButtonCallback(win, [](GLFWwindow * w, int button, int action, int mods)
{
auto s = (window*)glfwGetWindowUserPointer(win);
auto s = (window*)glfwGetWindowUserPointer(w);
if (button == 0) s->on_left_mouse(action == GLFW_PRESS);
});

glfwSetScrollCallback(win, [](GLFWwindow * win, double xoffset, double yoffset)
glfwSetScrollCallback(win, [](GLFWwindow * w, double xoffset, double yoffset)
{
auto s = (window*)glfwGetWindowUserPointer(win);
auto s = (window*)glfwGetWindowUserPointer(w);
s->on_mouse_scroll(xoffset, yoffset);
});

glfwSetCursorPosCallback(win, [](GLFWwindow * win, double x, double y)
glfwSetCursorPosCallback(win, [](GLFWwindow * w, double x, double y)
{
auto s = (window*)glfwGetWindowUserPointer(win);
auto s = (window*)glfwGetWindowUserPointer(w);
s->on_mouse_move(x, y);
});

glfwSetKeyCallback(win, [](GLFWwindow * win, int key, int scancode, int action, int mods)
glfwSetKeyCallback(win, [](GLFWwindow * w, int key, int scancode, int action, int mods)
{
auto s = (window*)glfwGetWindowUserPointer(win);
auto s = (window*)glfwGetWindowUserPointer(w);
if (0 == action) // on key release
{
s->on_key_release(key);
Expand Down
26 changes: 13 additions & 13 deletions examples/measure/rs-measure.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,16 @@ float dist_2d(const pixel& a, const pixel& b);
struct toggle
{
toggle() : x(0.f), y(0.f) {}
toggle(float x, float y)
: x(std::min(std::max(x, 0.f), 1.f)),
y(std::min(std::max(y, 0.f), 1.f))
toggle(float xl, float yl)
: x(std::min(std::max(xl, 0.f), 1.f)),
y(std::min(std::max(yl, 0.f), 1.f))
{}

// Move from [0,1] space to pixel space of specific frame
pixel get_pixel(rs2::depth_frame frame) const
pixel get_pixel(rs2::depth_frame frm) const
{
int px = x * frame.get_width();
int py = y * frame.get_height();
int px = x * frm.get_width();
int py = y * frm.get_height();
return{ px, py };
}

Expand Down Expand Up @@ -287,16 +287,16 @@ int main(int argc, char * argv[]) try
// Calculate distance in 3D between the two neighboring pixels
auto d = dist_3d(depth, u, v);
// Calculate total distance from source
auto total_dist = dist[u] + d;
auto total_distl = dist[u] + d;

// If we encounter a potential improvement,
if (dist[v] > total_dist)
if (dist[v] > total_distl)
{
// Update parent and distance
parent[v] = u;
dist[v] = total_dist;
dist[v] = total_distl;
// And re-visit that pixel by re-introducing it to the queue
q.emplace(total_dist, v);
q.emplace(total_distl, v);
}
}
}
Expand Down Expand Up @@ -496,9 +496,9 @@ void render_shortest_path(const rs2::depth_frame& depth,

for (int i = 0; i < path.size(); i++)
{
auto&& pixel = path[i];
auto x = (float(pixel.first) / depth.get_width()) * app.width();
auto y = (float(pixel.second) / depth.get_height()) * app.height();
auto&& pixel1 = path[i];
auto x = (float(pixel1.first) / depth.get_width()) * app.width();
auto y = (float(pixel1.second) / depth.get_height()) * app.height();
glVertex2f(x, y);

if (i == path.size() / 2) center = { x, y };
Expand Down
10 changes: 5 additions & 5 deletions examples/post-processing/rs-post-processing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -348,9 +348,9 @@ bool filter_slider_ui::is_all_integers(const rs2::option_range& range)
/**
Constructor for filter_options, takes a name and a filter.
*/
filter_options::filter_options(const std::string name, rs2::filter& filter) :
filter_options::filter_options(const std::string name, rs2::filter& flt) :
filter_name(name),
filter(filter),
filter(flt),
is_enabled(true)
{
const std::array<rs2_option, 3> possible_filter_options = {
Expand All @@ -362,13 +362,13 @@ filter_options::filter_options(const std::string name, rs2::filter& filter) :
//Go over each filter option and create a slider for it
for (rs2_option opt : possible_filter_options)
{
if (filter.supports(opt))
if (flt.supports(opt))
{
rs2::option_range range = filter.get_option_range(opt);
rs2::option_range range = flt.get_option_range(opt);
supported_options[opt].range = range;
supported_options[opt].value = range.def;
supported_options[opt].is_int = filter_slider_ui::is_all_integers(range);
supported_options[opt].description = filter.get_option_description(opt);
supported_options[opt].description = flt.get_option_description(opt);
std::string opt_name = rs2_option_to_string(opt);
supported_options[opt].name = name + "_" + opt_name;
std::string prefix = "Filter ";
Expand Down
6 changes: 3 additions & 3 deletions third-party/imgui/imgui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6518,10 +6518,10 @@ bool ImGui::SliderBehavior(const ImRect& frame_bb, ImGuiID id, float* v, float v
bb.Min.y -= 0.5;
bb.Max.y += 0.5;
}
float grab_padding = 2.0f;
float grab_paddingl = 2.0f;
//Horizontal fills from left to right
fill_br.Min = bb.Min;
fill_br.Max = ImVec2(ImLerp(bb.Min.x, bb.Max.x - grab_padding, *v / 100), bb.Max.y);
fill_br.Max = ImVec2(ImLerp(bb.Min.x, bb.Max.x - grab_paddingl, *v / 100), bb.Max.y);
graber_size = { grab_bb.Max.x - (width / 2.0f) , grab_bb.Max.y - (height / 2.0f) };
radius = height / 2.5f;
}
Expand All @@ -6534,7 +6534,7 @@ bool ImGui::SliderBehavior(const ImRect& frame_bb, ImGuiID id, float* v, float v
bb.Min.x -= 0.5;
bb.Max.x += 0.5;
}
float grab_padding = 2.0f;
float grab_paddingl = 2.0f;
//Vertical fills from down upwards
fill_br.Min = bb.Min;
fill_br.Min.y = grab_bb.Min.y;
Expand Down
58 changes: 29 additions & 29 deletions third-party/stb_image.h
Original file line number Diff line number Diff line change
Expand Up @@ -3468,7 +3468,7 @@ stbi_inline static int stbi__bit_reverse(int v, int bits)

static int stbi__zbuild_huffman(stbi__zhuffman *z, stbi_uc *sizelist, int num)
{
int i,k=0;
int i,kl=0;
int code, next_code[16], sizes[17];

// DEFLATE spec for generating codes
Expand All @@ -3484,13 +3484,13 @@ static int stbi__zbuild_huffman(stbi__zhuffman *z, stbi_uc *sizelist, int num)
for (i=1; i < 16; ++i) {
next_code[i] = code;
z->firstcode[i] = (stbi__uint16) code;
z->firstsymbol[i] = (stbi__uint16) k;
z->firstsymbol[i] = (stbi__uint16) kl;
code = (code + sizes[i]);
if (sizes[i])
if (code-1 >= (1 << i)) return stbi__err("bad codelengths","Corrupt PNG");
z->maxcode[i] = code << (16-i); // preshift for inner loop
code <<= 1;
k += sizes[i];
kl += sizes[i];
}
z->maxcode[16] = 0x10000; // sentinel
for (i=0; i < num; ++i) {
Expand All @@ -3501,10 +3501,10 @@ static int stbi__zbuild_huffman(stbi__zhuffman *z, stbi_uc *sizelist, int num)
z->size [c] = (stbi_uc ) s;
z->value[c] = (stbi__uint16) i;
if (s <= STBI__ZFAST_BITS) {
int k = stbi__bit_reverse(next_code[s],s);
while (k < (1 << STBI__ZFAST_BITS)) {
z->fast[k] = fastv;
k += (1 << s);
int kll = stbi__bit_reverse(next_code[s],s);
while (kll < (1 << STBI__ZFAST_BITS)) {
z->fast[kll] = fastv;
kll += (1 << s);
}
}
++next_code[s];
Expand Down Expand Up @@ -4110,20 +4110,20 @@ static int stbi__create_png_image_raw(stbi__png *a, stbi_uc *raw, stbi__uint32 r
}
if (img_n != out_n) {
// insert alpha = 255
stbi_uc *cur = a->out + stride*j;
int i;
stbi_uc *curl = a->out + stride*j;
int il;
if (img_n == 1) {
for (i=x-1; i >= 0; --i) {
cur[i*2+1] = 255;
cur[i*2+0] = cur[i];
for (il=x-1; il >= 0; --il) {
curl[il*2+1] = 255;
curl[il*2+0] = curl[il];
}
} else {
STBI_ASSERT(img_n == 3);
for (i=x-1; i >= 0; --i) {
cur[i*4+3] = 255;
cur[i*4+2] = cur[i*3+2];
cur[i*4+1] = cur[i*3+1];
cur[i*4+0] = cur[i*3+0];
for (il=x-1; il >= 0; --il) {
curl[il*4+3] = 255;
curl[il*4+2] = curl[il*3+2];
curl[il*4+1] = curl[il*3+1];
curl[il*4+0] = curl[il*3+0];
}
}
}
Expand Down Expand Up @@ -4908,8 +4908,8 @@ static stbi_uc *stbi__tga_load(stbi__context *s, int *x, int *y, int *comp, int

if ( !tga_indexed && !tga_is_RLE) {
for (i=0; i < tga_height; ++i) {
int y = tga_inverted ? tga_height -i - 1 : i;
stbi_uc *tga_row = tga_data + y*tga_width*tga_comp;
int yl = tga_inverted ? tga_height -i - 1 : i;
stbi_uc *tga_row = tga_data + yl*tga_width*tga_comp;
stbi__getn(s, tga_row, tga_width * tga_comp);
}
} else {
Expand Down Expand Up @@ -5350,7 +5350,7 @@ static stbi_uc *stbi__pic_load_core(stbi__context *s,int width,int height,int *c

if (count >= 128) { // Repeated
stbi_uc value[4];
int i;
int il;

if (count==128)
count = stbi__get16be(s);
Expand All @@ -5362,7 +5362,7 @@ static stbi_uc *stbi__pic_load_core(stbi__context *s,int width,int height,int *c
if (!stbi__readval(s,packet->channel,value))
return 0;

for(i=0;i<count;++i, dest += 4)
for(il=0;il<count;++il, dest += 4)
stbi__copyval(packet->channel,dest,value);
} else { // Raw
++count;
Expand Down Expand Up @@ -5592,41 +5592,41 @@ static stbi_uc *stbi__process_gif_raster(stbi__context *s, stbi__gif *g)
bits |= (stbi__int32) stbi__get8(s) << valid_bits;
valid_bits += 8;
} else {
stbi__int32 code = bits & codemask;
stbi__int32 codel = bits & codemask;
bits >>= codesize;
valid_bits -= codesize;
// @OPTIMIZE: is there some way we can accelerate the non-clear path?
if (code == clear) { // clear code
if (codel == clear) { // clear code
codesize = lzw_cs + 1;
codemask = (1 << codesize) - 1;
avail = clear + 2;
oldcode = -1;
first = 0;
} else if (code == clear + 1) { // end of stream code
} else if (codel == clear + 1) { // end of stream code
stbi__skip(s, len);
while ((len = stbi__get8(s)) > 0)
stbi__skip(s,len);
return g->out;
} else if (code <= avail) {
} else if (codel <= avail) {
if (first) return stbi__errpuc("no clear code", "Corrupt GIF");

if (oldcode >= 0) {
p = &g->codes[avail++];
if (avail > 4096) return stbi__errpuc("too many codes", "Corrupt GIF");
p->prefix = (stbi__int16) oldcode;
p->first = g->codes[oldcode].first;
p->suffix = (code == avail) ? p->first : g->codes[code].first;
} else if (code == avail)
p->suffix = (codel == avail) ? p->first : g->codes[codel].first;
} else if (codel == avail)
return stbi__errpuc("illegal code in raster", "Corrupt GIF");

stbi__out_gif_code(g, (stbi__uint16) code);
stbi__out_gif_code(g, (stbi__uint16) codel);

if ((avail & codemask) == 0 && avail <= 0x0FFF) {
codesize++;
codemask = (1 << codesize) - 1;
}

oldcode = code;
oldcode = codel;
} else {
return stbi__errpuc("illegal code in raster", "Corrupt GIF");
}
Expand Down
2 changes: 1 addition & 1 deletion tools/data-collect/rs-data-collect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ data_collector::data_collector(std::shared_ptr<rs2::device> dev,
_time_out_sec = timeout.isSet() ? timeout.getValue() : -1;

_stop_cond = static_cast<application_stop>((int(max_frames.isSet()) << 1) + int(timeout.isSet()));
};
}

void data_collector::parse_and_configure(ValueArg<string>& config_file)
{
Expand Down

0 comments on commit 7dc02e2

Please sign in to comment.