Skip to content

Commit

Permalink
avoid segfault when buffer size is too small
Browse files Browse the repository at this point in the history
git-svn-id: http://brown-ros-pkg.googlecode.com/svn/trunk/experimental/gscam@2756 0d49d21e-669f-11de-873c-fb8c264d332a
  • Loading branch information
[email protected] committed May 8, 2012
1 parent 7de52ed commit d7e7916
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/gscam.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -158,8 +158,19 @@ int main(int argc, char** argv) {
gst_structure_get_int(structure,"width",&width);
gst_structure_get_int(structure,"height",&height);

// Don't segfault if we get an unexpected buffer size
if (buf->size < width * height * 3) {
static bool warning = false;
if (!warning) {
warning = true;
std::cout << "warning: expected frame to be " << (width * height * 3) << " bytes but got only "
<< buf->size << " bytes, ignoring unusable frames (make sure frames are raw RGB encoded)" << std::endl;
}
continue;
}

sensor_msgs::Image msg;
msg.width = width;
msg.width = width;
msg.height = height;
msg.encoding = "rgb8";
msg.is_bigendian = false;
Expand Down

0 comments on commit d7e7916

Please sign in to comment.