From fcfd2d5da151f0035dc79a60552aadbd4ed408ad Mon Sep 17 00:00:00 2001 From: Luis Lucas Date: Mon, 6 Jun 2016 13:51:39 +0100 Subject: [PATCH] Fix crashing when actual number of bits is larger than the specified one. --- CMakeLists.txt | 2 +- lib/PlaYUVerFrame.cpp | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index efb8a14..3912c0d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -148,7 +148,7 @@ IF( USE_WERROR ) SET( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror" ) ENDIF() -SET( CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -g" ) +SET( CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -g -O0" ) SET( CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O2" ) diff --git a/lib/PlaYUVerFrame.cpp b/lib/PlaYUVerFrame.cpp index 4ddd1af..9a012b0 100644 --- a/lib/PlaYUVerFrame.cpp +++ b/lib/PlaYUVerFrame.cpp @@ -576,6 +576,7 @@ Void PlaYUVerFrame::frameFromBuffer( Byte *Buff ) Int endByte = bytesPixel; Int incByte = 1; Int b; + Int maxval = pow(2, d->m_uiBitsPel) - 1; if( d->m_iEndianness == 0 ) { @@ -608,6 +609,10 @@ Void PlaYUVerFrame::frameFromBuffer( Byte *Buff ) { *pPel += *pTmpBuff << ( b * 8 ); pTmpBuff++; + // Check max value and bound it to "maxval" to prevent segfault when calculating histogram + if(*pPel > maxval) + *pPel = 0; + // ----- } pPel++; pTmpBuff += step;