void clear_screen_buf() { int y, x; for (y=0; y < SCREEN_Y; ++y){ for (x=0; x < SCREEN_X; ++x){ CHECK_BOUNDS(y,x); screen_buf[y][x] = ' '; } CHECK_BOUNDS(y,SCREEN_X); screen_buf[y][SCREEN_X] = '\0'; } }
/// (start/end are included in the result) void DataStream::crop(int start, int end){ CHECK_BOUNDS(start, 0, frames.size()); CHECK_BOUNDS(end, 0, frames.size()); CHECK(start<end); /// mark frame id as invalid in the range for(int i=0; i<frames.size(); i++) if(i<start || i>end) frames.at(i)->id = -1; /// now let std take over auto lambda = [](const DataFrame* f) { return (f->id==-1); }; frames.erase(std::remove_if(frames.begin(), frames.end(), lambda), frames.end()); }
inline void MakeScalarValueImpl(GfVec3h *out, vector<Value> const &vars, size_t &index) { CHECK_BOUNDS(3, "Vec3h"); (*out)[0] = GfHalf(vars[index++].Get<float>()); (*out)[1] = GfHalf(vars[index++].Get<float>()); (*out)[2] = GfHalf(vars[index++].Get<float>()); }
inline void MakeScalarValueImpl(GfVec3i *out, vector<Value> const &vars, size_t &index) { CHECK_BOUNDS(3, "Vec3i"); (*out)[0] = vars[index++].Get<int>(); (*out)[1] = vars[index++].Get<int>(); (*out)[2] = vars[index++].Get<int>(); }
char get_scrn_buf(const int y, const int x) { CHECK_BOUNDS(y,x); return screen_buf[y][x]; }
inline void MakeScalarValueImpl(GfVec2d *out, vector<Value> const &vars, size_t &index) { CHECK_BOUNDS(2, "Vec2d"); (*out)[0] = vars[index++].Get<double>(); (*out)[1] = vars[index++].Get<double>(); }
inline void MakeScalarValueImpl(GfVec4f *out, vector<Value> const &vars, size_t &index) { CHECK_BOUNDS(4, "Vec4f"); (*out)[0] = vars[index++].Get<float>(); (*out)[1] = vars[index++].Get<float>(); (*out)[2] = vars[index++].Get<float>(); (*out)[3] = vars[index++].Get<float>(); }
void set_scrn_buf(const int y, const int x, const char val) { CHECK_BOUNDS(y,x); screen_buf[y][x] = val; }
inline void MakeScalarValueImpl(GfQuath *out, vector<Value> const &vars, size_t &index) { CHECK_BOUNDS(4, "Quath"); // Values in order are re, i, j, k. GfVec3h imag; GfHalf re; MakeScalarValueImpl(&re, vars, index); out->SetReal(re); MakeScalarValueImpl(&imag, vars, index); out->SetImaginary(imag); }
void tty_print_region(const int pi_top, const int pi_left, const int pi_bottom, const int pi_right) { int y; char tmp; for (y=pi_top; y < pi_bottom; ++y){ CHECK_BOUNDS(y, pi_right); tmp = screen_buf[y][pi_right]; screen_buf[y][pi_right] = '\0'; CHECK_BOUNDS(y, pi_left); ttyprint(y, pi_left, &(screen_buf[y][pi_left])); screen_buf[y][pi_right] = tmp; } }
inline void MakeScalarValueImpl(GfMatrix3d *out, vector<Value> const &vars, size_t &index) { CHECK_BOUNDS(9, "Matrix3d"); (*out)[0][0] = vars[index++].Get<double>(); (*out)[0][1] = vars[index++].Get<double>(); (*out)[0][2] = vars[index++].Get<double>(); (*out)[1][0] = vars[index++].Get<double>(); (*out)[1][1] = vars[index++].Get<double>(); (*out)[1][2] = vars[index++].Get<double>(); (*out)[2][0] = vars[index++].Get<double>(); (*out)[2][1] = vars[index++].Get<double>(); (*out)[2][2] = vars[index++].Get<double>(); }
BOOL vmsDownloadMgrEx::LoadState(LPBYTE lpBuffer, LPDWORD lpdwSize, WORD wVer) { #define CHECK_BOUNDS(need) if (need < 0 || need > int(*lpdwSize) - (pB - LPBYTE (lpBuffer))) return FALSE; LPBYTE pB = LPBYTE (lpBuffer); BYTE bBitTorrent = FALSE, bTransportProtocol = FALSE; DWORD dwMgrStateSize = *lpdwSize; DWORD dwConsumed = 0; BOOL bOk; if (wVer > 9) { CHECK_BOUNDS (sizeof (BYTE)); const int nMgr = *lpBuffer++; bBitTorrent = (nMgr == 1); if (wVer > 13) bTransportProtocol = (nMgr == 2); dwConsumed++; dwMgrStateSize--; } if (bTransportProtocol) { Attach (new vmsTpDownloadMgr); bOk = m_pTpMgr->LoadState (lpBuffer, &dwMgrStateSize, wVer); } else if (bBitTorrent) { vmsBtDownloadManagerPtr spMgr; spMgr.CreateInstance (); Attach (spMgr); bOk = m_spBtMgr->LoadState (lpBuffer, &dwMgrStateSize, wVer); } else { Attach (new fsDownloadMgr); bOk = m_pMgr->LoadState (lpBuffer, &dwMgrStateSize, wVer); } if (bOk == FALSE) return FALSE; dwConsumed += dwMgrStateSize; *lpdwSize = dwConsumed; return TRUE; }
inline void MakeScalarValueImpl( SdfAssetPath *out, vector<Value> const &vars, size_t &index) { CHECK_BOUNDS(1, "asset"); *out = vars[index++].Get<SdfAssetPath>(); }
inline typename boost::enable_if<boost::is_integral<Int> >::type MakeScalarValueImpl(Int *out, vector<Value> const &vars, size_t &index) { CHECK_BOUNDS(1, ArchGetDemangled<Int>().c_str()); *out = vars[index++].Get<Int>(); }
inline int array_get_value(void* array, int pos) { CHECK_BOUNDS(array, pos); return ((int*)array)[pos]; }
void AGOSEngine::freeBox(uint index) { CHECK_BOUNDS(index, _hitAreas); _hitAreas[index].flags = 0; }
inline void array_set_value(void* array, int pos, int val) { CHECK_BOUNDS(array, pos); ((int*)array)[pos]=val; }
inline void MakeScalarValueImpl(float *out, vector<Value> const &vars, size_t &index) { CHECK_BOUNDS(1, "float"); *out = vars[index++].Get<float>(); }
void AGOSEngine::printVerbOf(uint hitarea_id) { const char *txt; const char * const *verb_names; const char * const *verb_prep_names; hitarea_id -= 101; if (_showPreposition) { switch (_language) { case Common::RU_RUS: verb_prep_names = russian_verb_prep_names; break; case Common::HE_ISR: verb_prep_names = hebrew_verb_prep_names; break; case Common::ES_ESP: verb_prep_names = spanish_verb_prep_names; break; case Common::IT_ITA: verb_prep_names = italian_verb_prep_names; break; case Common::FR_FRA: verb_prep_names = french_verb_prep_names; break; case Common::DE_DEU: verb_prep_names = german_verb_prep_names; break; case Common::CZ_CZE: verb_prep_names = czech_verb_prep_names; break; default: verb_prep_names = english_verb_prep_names; break; } CHECK_BOUNDS(hitarea_id, english_verb_prep_names); txt = verb_prep_names[hitarea_id]; } else { switch (_language) { case Common::RU_RUS: verb_names = russian_verb_names; break; case Common::HE_ISR: verb_names = hebrew_verb_names; break; case Common::ES_ESP: verb_names = spanish_verb_names; break; case Common::IT_ITA: verb_names = italian_verb_names; break; case Common::FR_FRA: verb_names = french_verb_names; break; case Common::DE_DEU: verb_names = german_verb_names; break; case Common::CZ_CZE: verb_names = czech_verb_names; break; default: verb_names = english_verb_names; break; } CHECK_BOUNDS(hitarea_id, english_verb_names); txt = verb_names[hitarea_id]; } showActionString((const byte *)txt); }
inline void MakeScalarValueImpl(TfToken *out, vector<Value> const &vars, size_t &index) { CHECK_BOUNDS(1, "token"); *out = TfToken(vars[index++].Get<std::string>()); }
inline void MakeScalarValueImpl(double *out, vector<Value> const &vars, size_t &index) { CHECK_BOUNDS(1, "double"); *out = vars[index++].Get<double>(); }
inline void MakeScalarValueImpl(GfHalf *out, vector<Value> const &vars, size_t &index) { CHECK_BOUNDS(1, "half"); *out = GfHalf(vars[index++].Get<float>()); }
BOOL vmsTpDownloadMgr::LoadState(LPBYTE lpBuffer, LPDWORD pdwSize, WORD wVer) { vmsAUTOLOCKSECTION (m_csDownload); ASSERT (wVer >= 14); #define CHECK_BOUNDS(need) if (need < 0 || need > int(*pdwSize) - (pB - LPBYTE (lpBuffer))) return FALSE; LPBYTE pB = (LPBYTE) lpBuffer; int i; char sz [10000]; CHECK_BOUNDS (sizeof (int)); CopyMemory (&i, pB, sizeof (int)); pB += sizeof (int); CHECK_BOUNDS (int (i)); CopyMemory (sz, pB, i); sz [i] = 0; fsString pszUrl = sz; pB += i; CHECK_BOUNDS (sizeof (int)); CopyMemory (&i, pB, sizeof (int)); pB += sizeof (int); CHECK_BOUNDS (int (i)); CopyMemory (sz, pB, i); sz [i] = 0; fsString pszOutputPath = sz; pB += i; CHECK_BOUNDS (sizeof (int)); CopyMemory (&i, pB, sizeof (int)); pB += sizeof (int); CHECK_BOUNDS (int (i)); CopyMemory (sz, pB, i); sz [i] = 0; fsString pszFileName = sz; pB += i; CHECK_BOUNDS (sizeof (int)); CopyMemory (&m_info.nStreamingSpeed, pB, sizeof (int)); pB += sizeof (int); CHECK_BOUNDS (sizeof (int)); CopyMemory (&m_info.nNumSections, pB, sizeof (int)); pB += sizeof (int); CHECK_BOUNDS (sizeof (UINT64)); CopyMemory (&m_info.nFileSize, pB, sizeof (UINT64)); pB += sizeof (UINT64); CHECK_BOUNDS (sizeof (m_info.bDone)); CopyMemory (&m_info.bDone, pB, sizeof (m_info.bDone)); pB += sizeof (m_info.bDone); CHECK_BOUNDS (sizeof (m_info.fPercentDone)); CopyMemory (&m_info.fPercentDone, pB, sizeof (m_info.fPercentDone)); pB += sizeof (m_info.fPercentDone); CHECK_BOUNDS (sizeof (m_info.nDownloadedBytes)); CopyMemory (&m_info.nDownloadedBytes, pB, sizeof (m_info.nDownloadedBytes)); pB += sizeof (m_info.nDownloadedBytes); if(!CreateTPDownload(pszUrl, pszOutputPath, pszFileName, i)) return FALSE; *pdwSize = pB - (LPBYTE) lpBuffer; return TRUE; }
bool fsDownload::loadObjectItselfFromStateBuffer(LPBYTE pb, LPDWORD pdwSize, DWORD dwVer) { #define CHECK_BOUNDS(need) if (need < 0 || need > int(*pdwSize) - (pB - LPBYTE (pb))) return false; LPBYTE pB = LPBYTE (pb); DWORD dw = *pdwSize; LPSTR szStr; int iReserved; CHECK_BOUNDS (sizeof (DWORD)); pB += sizeof (DWORD); if (pMgr == 0) return false; CHECK_BOUNDS (sizeof (BYTE)); BYTE btType = *pB++; switch (btType) { case 0: { fsDownloadMgr* pdmMgr = new fsDownloadMgr(); pMgr->Attach (pdmMgr); } break; case 1: { vmsBtDownloadManagerPtr spMgr; spMgr.CreateInstance (); pMgr->Attach (spMgr); } break; case 2: { vmsTpDownloadMgr* ptdmMgr = new vmsTpDownloadMgr(); pMgr->Attach (ptdmMgr); } break; default: return false; } CHECK_BOUNDS (sizeof (bAutoStart)); CopyMemory (&bAutoStart, pB, sizeof (bAutoStart)); pB += sizeof (bAutoStart); CHECK_BOUNDS (sizeof (iReserved)); CopyMemory (&iReserved, pB, sizeof (iReserved)); pB += sizeof (iReserved); CHECK_BOUNDS (sizeof (nID)); CopyMemory (&nID, pB, sizeof (nID)); pB += sizeof (nID); CHECK_BOUNDS (sizeof (dw)); CopyMemory (&dw, pB, sizeof (dw)); CHECK_BOUNDS (int (dw)); pB += sizeof (dw); fsnew (szStr, CHAR, dw+1); CopyMemory (szStr, pB, dw); szStr [dw] = 0; strComment = szStr; delete [] szStr; pB += dw; if (dwVer < 9) { CHECK_BOUNDS (sizeof (dw)); CopyMemory (&dw, pB, sizeof (dw)); CHECK_BOUNDS (int (dw)); pB += sizeof (dw); fsnew (szStr, CHAR, dw+1); CopyMemory (szStr, pB, dw); szStr [dw] = 0; pGroup = _DldsGrps.FindGroupByName (szStr); delete [] szStr; pB += dw; } else { UINT nGrpId; CHECK_BOUNDS (sizeof (UINT)); CopyMemory (&nGrpId, pB, sizeof (UINT)); pB += sizeof (UINT); pGroup = _DldsGrps.FindGroup (nGrpId); } if (pGroup == NULL) pGroup = _DldsGrps.FindGroup (GRP_OTHER_ID); CHECK_BOUNDS (sizeof (dwFlags)); CopyMemory (&dwFlags, pB, sizeof (dwFlags)); pB += sizeof (dwFlags); CHECK_BOUNDS (sizeof (dwReserved)); CopyMemory (&dwReserved, pB, sizeof (dwReserved)); pB += sizeof (dwReserved); CHECK_BOUNDS (sizeof (dateAdded)); CopyMemory (&dateAdded, pB, sizeof (dateAdded)); pB += sizeof (dateAdded); if (dwVer >= 15) { CHECK_BOUNDS (sizeof (dateCompleted)); CopyMemory (&dateCompleted, pB, sizeof (dateCompleted)); pB += sizeof (dateCompleted); } DWORD cEvents; CHECK_BOUNDS (sizeof (cEvents)); CopyMemory (&cEvents, pB, sizeof (cEvents)); pB += sizeof (cEvents); vEvents.clear (); while (cEvents--) { fsDownloadEvents ev; CHECK_BOUNDS (sizeof (ev.clrBg)); CopyMemory (&ev.clrBg, pB, sizeof (ev.clrBg)); pB += sizeof (ev.clrBg); CHECK_BOUNDS (sizeof (ev.clrText)); CopyMemory (&ev.clrText, pB, sizeof (ev.clrText)); pB += sizeof (ev.clrText); CHECK_BOUNDS (sizeof (ev.timeEvent)); CopyMemory (&ev.timeEvent, pB, sizeof (ev.timeEvent)); pB += sizeof (ev.timeEvent); CHECK_BOUNDS (sizeof (ev.iImage)); CopyMemory (&ev.iImage, pB, sizeof (ev.iImage)); pB += sizeof (ev.iImage); CHECK_BOUNDS (sizeof (dw)); CopyMemory (&dw, pB, sizeof (dw)); CHECK_BOUNDS (int (dw)); pB += sizeof (dw); fsnew (szStr, CHAR, dw+1); CopyMemory (szStr, pB, dw); szStr [dw] = 0; ev.strEvent = szStr; delete [] szStr; pB += dw; vEvents.add (ev); } *pdwSize = pB - LPBYTE (pb); return true; }
static int mdss_mdp_overlay_req_check(struct msm_fb_data_type *mfd, struct mdp_overlay *req, struct mdss_mdp_format_params *fmt) { u32 xres, yres; xres = mfd->fbi->var.xres; yres = mfd->fbi->var.yres; if (req->z_order >= MDSS_MDP_MAX_STAGE) { pr_err("zorder %d out of range\n", req->z_order); return -ERANGE; } if (req->src.width > MAX_IMG_WIDTH || req->src.height > MAX_IMG_HEIGHT || req->src_rect.w == 0 || req->src_rect.h == 0 || CHECK_BOUNDS(req->src_rect.x, req->src_rect.w, req->src.width) || CHECK_BOUNDS(req->src_rect.y, req->src_rect.h, req->src.height)) { pr_err("invalid source image img wh=%dx%d rect=%d,%d,%d,%d\n", req->src.width, req->src.height, req->src_rect.x, req->src_rect.y, req->src_rect.w, req->src_rect.h); return -EOVERFLOW; } if (req->dst_rect.w < MIN_DST_W || req->dst_rect.h < MIN_DST_H || req->dst_rect.w > MAX_DST_W || req->dst_rect.h > MAX_DST_H) { pr_err("invalid destination resolution (%dx%d)", req->dst_rect.w, req->dst_rect.h); return -EOVERFLOW; } if (req->flags & MDSS_MDP_ROT_ONLY) { /* dst res should match src res in rotation only mode*/ req->dst_rect.w = req->src_rect.w; req->dst_rect.h = req->src_rect.h; } else { u32 dst_w, dst_h; if ((CHECK_BOUNDS(req->dst_rect.x, req->dst_rect.w, xres) || CHECK_BOUNDS(req->dst_rect.y, req->dst_rect.h, yres))) { pr_err("invalid destination rect=%d,%d,%d,%d\n", req->dst_rect.x, req->dst_rect.y, req->dst_rect.w, req->dst_rect.h); return -EOVERFLOW; } if (req->flags & MDP_ROT_90) { dst_h = req->dst_rect.w; dst_w = req->dst_rect.h; } else { dst_w = req->dst_rect.w; dst_h = req->dst_rect.h; } if ((req->src_rect.w * MAX_UPSCALE_RATIO) < dst_w) { pr_err("too much upscaling Width %d->%d\n", req->src_rect.w, req->dst_rect.w); return -EINVAL; } if ((req->src_rect.h * MAX_UPSCALE_RATIO) < dst_h) { pr_err("too much upscaling. Height %d->%d\n", req->src_rect.h, req->dst_rect.h); return -EINVAL; } if (req->src_rect.w > (dst_w * MAX_DOWNSCALE_RATIO)) { pr_err("too much downscaling. Width %d->%d\n", req->src_rect.w, req->dst_rect.w); return -EINVAL; } if (req->src_rect.h > (dst_h * MAX_DOWNSCALE_RATIO)) { pr_err("too much downscaling. Height %d->%d\n", req->src_rect.h, req->dst_rect.h); return -EINVAL; } if ((fmt->chroma_sample == MDSS_MDP_CHROMA_420 || fmt->chroma_sample == MDSS_MDP_CHROMA_H2V1) && ((req->src_rect.w * (MAX_UPSCALE_RATIO / 2)) < dst_w)) { pr_err("too much YUV upscaling Width %d->%d\n", req->src_rect.w, req->dst_rect.w); return -EINVAL; } if ((fmt->chroma_sample == MDSS_MDP_CHROMA_420 || fmt->chroma_sample == MDSS_MDP_CHROMA_H1V2) && (req->src_rect.h * (MAX_UPSCALE_RATIO / 2)) < dst_h) { pr_err("too much YUV upscaling Height %d->%d\n", req->src_rect.h, req->dst_rect.h); return -EINVAL; } } if (fmt->is_yuv) { if ((req->src_rect.x & 0x1) || (req->src_rect.y & 0x1) || (req->src_rect.w & 0x1) || (req->src_rect.h & 0x1)) { pr_err("invalid odd src resolution or coordinates\n"); return -EINVAL; } if ((req->dst_rect.w & 0x1) || (req->dst_rect.h & 0x1)) { pr_err("invalid odd dst resolution\n"); return -EINVAL; } } return 0; }
INITIALIZE_EASYLOGGINGPP int main(void) { el::Loggers::addFlag(el::LoggingFlag::DisableApplicationAbortOnFatalLog); // These checks should fail LOG(INFO) << "----- DONT WORRY ABOUT FOLLOWING CHECKS FAILING - THEY ARE EXPECTED"; CHECK(1 > 2) << "1 is not greater than 2"; CHECK_EQ(1, 2) << "1 is not equal to 2"; CHECK_NE(1, 1) << "Wow, I did not know 1 == 1"; CHECK_STREQ("abc", "def") << " :)"; CHECK_STRNE("abc", "abc") << " :("; CHECK_STRCASEEQ("abc", "ABCD") << " :p"; CHECK_STRCASENE("abc", "ABC") << " B)"; int* f = new int; CHECK_NOTNULL(f); delete f; f = nullptr; // These checks should pass LOG(WARNING) << "----- START WORRYING ABOUT CHECKS NOW"; CHECK(1 < 2) << " snap -- lib has bug!"; CHECK_EQ(1, 1) << " snap -- lib has bug!"; CHECK_NE(1, 2) << " snap -- lib has bug!"; CHECK_STREQ("abc", "abc") << " snap -- lib has bug!"; CHECK_STRNE("abc", "abe") << " snap -- lib has bug!"; CHECK_STRCASEEQ("abc", "ABC") << " snap -- lib has bug!"; CHECK_STRCASENE("abc", "ABE") << " snap -- lib has bug!"; LOG(INFO) << "----- HOPEFULLY NO CHECK FAILED SINCE YOU STARTED WORRYING!"; // DCHECKs DCHECK(1 > 2) << "1 is not greater than 2"; DCHECK_EQ(1, 2) << "1 is not equal to 2"; DCHECK_NE(1, 1) << "Wow, I did not know 1 == 1"; DCHECK_STREQ("abc", "def") << " :)"; DCHECK_STRNE("abc", "abc") << " :("; DCHECK_STRCASEEQ("abc", "ABCD") << " :p"; DCHECK_STRCASENE("abc", "ABC") << " B)"; // PCHECKs std::fstream fstr("a/file/that/does/not/exist", std::fstream::in); PCHECK(fstr.is_open()); DPCHECK(fstr.is_open()); int min = 1; int max = 5; CHECK_BOUNDS(1, min, max) << "Index out of bounds"; CHECK_BOUNDS(2, min, max) << "Index out of bounds"; CHECK_BOUNDS(3, min, max) << "Index out of bounds"; CHECK_BOUNDS(4, min, max) << "Index out of bounds"; CHECK_BOUNDS(5, min, max) << "Index out of bounds"; CHECK_BOUNDS(6, min, max) << "Index out of bounds"; DCHECK_BOUNDS(1, min, max) << "Index out of bounds"; DCHECK_BOUNDS(2, min, max) << "Index out of bounds"; DCHECK_BOUNDS(3, min, max) << "Index out of bounds"; DCHECK_BOUNDS(4, min, max) << "Index out of bounds"; DCHECK_BOUNDS(5, min, max) << "Index out of bounds"; DCHECK_BOUNDS(6, min, max) << "Index out of bounds"; return 0; }