草庐IT

integer-overflow

全部标签

c++ - libpng 错误 : PNG unsigned integer out of range

当尝试从内存中读取PNG时,我遇到了这个奇怪的错误:libpngerror::PNGunsignedintegeroutofrange这个错误是由引起的png_read_info(png_ptr,info_ptr);它使用以下处理程序:staticvoidReadDataFromBuffer(png_structppng_ptr,png_bytepoutBytes,png_size_tbyteCountToRead){PNGDataPtrdataptr=(PNGDataPtr)png_get_io_ptr(png_ptr);png_uint_32i;coutlenpdataptr->l

c++ - 2 个重载具有相似的转换 - 内置运算符 integer[pointer-to-object]

我有以下类(class):classDictionaryRef{public:operatorbool()const;std::stringconst&operator[](std::stringconst&name)const;//...};然后我尝试使用它:DictionaryRefref=...;ref["asdf"];//error输出提示两个重载,但只列出一个:1>...:errorC2666:'DictionaryRef::operator[]':2overloadshavesimilarconversions1>...:couldbe'conststd::string&D

c++ - 创建一个自定义整数,强制始终在指定范围内;如何克服整数溢出?

如题。作为练习,我想创建一个int来对其值施加约束,并且不允许将其设置为指定范围之外的值。这是我尝试解决这个问题的方法:#include#include#includeusingnamespacestd;intmain();templateclassConstrainedValue{valtypeval;staticboolcheckval(valtypeval){returnminvalval=val;return*this;}operatorconstvaltype&()//Notneededherebutcanbe;safesinceitreturnsaconstreferenc

c++ - Valgrind 报告 "brk segment overflow in thread #1"

这个问题在这里已经有了答案:Valgrindreportingasegmentoverflow(5个答案)关闭5年前。我想知道这条消息意味着什么:==18151==brksegmentoverflowinthread#1:can'tgrowto0x4a26000请注意,代码运行良好并且输出正确。我应该忽略这条消息吗?这是什么意思?

c++ - 预处理器 "invalid integer constant expression"比较 int 和 double

在我的代码中的某处,我有预处理器定义#defineZOOM_FACTOR1我在另一个地方#ifdefZOOM_FACTOR#if(ZOOM_FACTOR==1)#defineFONT_SIZE8#else#defineFONT_SIZE12#endif#else#defineFONT_SIZE8#endif问题是当我将ZOOM_FACTOR值更改为float值时,例如1.5,出现编译错误C1017:无效的整数常量表达式。有谁知道我为什么会收到这个错误,有没有办法在预处理器指令中比较integer和floatingpointnumber? 最佳答案

c++ - std::map 在低内存情况下导致 "stack overflow"

此应用程序正在使用C++在WindowsXP上的VS2010中开发。当计算机在物理内存上运行时非常低(并且页面文件被禁用,因为它是我们的测试用例),这行代码:std::map>MyMap;在malloc.c中导致“堆栈溢出”错误'returnHeapAlloc(_crtheap,0,size?size:1);'MyApp.exe中0x7c90e8e5处的未处理异常:0xC00000FD:堆栈溢出。此调用是从应用程序的线程之一进行的。如果内存不足是错误,它应该抛出bad_alloc谁能告诉我这里可能是什么原因。编辑:这是实际堆栈的样子ntdll.dll!7c90e8e5()[Frames

c++ - libpng png_set_add_alpha | png_set_filler 错误 : sequential row overflow

我正在尝试使用C读取PNG文件以用于OpenCL。OpenCL不支持24位RGB图像,因此我需要将数据从RGB扩展到RGBA。我使用的PNG都是24位的,因此可以避免头痛。我曾尝试使用png_set_filler和png_set_add_alpha,我认为它们大致相同来解决问题,但它们都会导致此错误:libpngerror:sequentialrowoverflow这里是完整的函数:intLoadPNG24(unsignedchar**pixelBuffer,constchar*filename,unsignedint*width,unsignedint*height){png_byt

c++ - "-ftrapv"和 "-fwrapv": Which is better for efficiency?

来自GNU的网站:-ftrapvThisoptiongeneratestrapsforsignedoverflowonaddition,subtraction,multiplicationoperations.-fwrapvThisoptioninstructsthecompilertoassumethatsignedarithmeticoverflowofaddition,subtractionandmultiplicationwrapsaroundusingtwos-complementrepresentation.Thisflagenablessomeoptimizationsa

c++ - 左移位和丢弃位

让我们考虑将无符号短值(或任何其他无符号整数类型)的右N位清零的函数(它的可能实现之一)。可能的实现如下所示:templateunsignedshortzero_right(unsignedshortarg){usingtype=unsignedshort;constexprtypemask=~(type(0));constexprtyperight_zeros=mask(16);}使用这段代码,我有权访问的所有编译器都会以某种方式提示可能的溢出。CLang是最明确的,具有以下明确信息:error:implicitconversionfrom'int'to'consttype'(aka

c++ - gcc "overflow in expression"而等效等效表达式工作正常

这是我的代码#includestaticconstunsignedlonglongintxx=(36*36*36*36)*(36*36*36*36);staticconstunsignedlonglonginty=36*36*36*36;staticconstunsignedlonglongintyy=y*y;intmain(){std::cout这是编译输出#g++-std=c++11test.cpp-otesttest.cpp:2:62:warning:integeroverflowinexpression[-Woverflow]staticconstunsignedlonglon