甲钴胺治什么病| 西洋参泡水喝有什么好处| 李开复是什么人| 劳改是什么意思| 生育登记服务单是什么| 煞南是什么意思| 青蛙为什么晚上叫| 不孕不育的症状是什么| 皮秒是什么| 什么叫收缩压和舒张压| 粉玫瑰适合送什么人| 今年是什么年号| 有时头晕是什么原因| 肠镜检查前需要做什么准备工作| 话少一般都是什么人| 嘴唇舌头发麻什么病兆| 胩是什么意思| 卵巢囊肿是什么引起的| 什么息| 孔雀鱼吃什么| 姚晨为什么不红了| 红色的菜叫什么| 煊字五行属什么| 造化什么意思| 成佛是什么意思| 不锈钢肥皂是什么原理| 孕晚期流鼻血是什么原因| 耳朵嗡嗡响是什么原因| 便秘什么意思| 阳虚吃什么好| 感冒流鼻涕吃什么药| 男士长脸适合什么发型| 端午是什么时候| apm是什么| 小孩子经常流鼻血是什么原因| 鸭子为什么会游泳| 舌苔厚白湿气重吃什么药| 苹果手机为什么充不进去电| 后援会是什么意思| 马超属什么生肖| 崖柏对人体有什么好处| 驾驶证体检挂什么科| 一抽一抽的打嗝叫什么| 增强ct是什么| 维生素c对身体有什么好处| hoka跑鞋中文叫什么| 鬼火是什么意思| 单字五行属什么| 亨廷顿舞蹈症是什么病| tasty是什么意思| 送同学什么生日礼物好| 人死了是什么感觉| 阴虚阳亢是什么意思| 什么蔬菜补铁| 女人味是什么| 癣是什么原因引起的| 胃胀气打嗝是什么原因| 慢性萎缩性胃炎c2是什么意思| 边缘视力是什么意思| 长期喝山楂水有什么好处和坏处| 休克是什么症状| 小肚子胀是什么原因| 肾不好会出现什么症状| 双肺纹理增多是什么意思严重吗| 什么样的小鸟| 喝生姜水有什么好处| 缺铁性贫血的人吃什么补血最快| 什么网站可以看黄色视频| 反酸是什么意思| 隐喻的意思是什么| 小孩为什么会流鼻血| 茉莉茶叶有什么功效和作用| 为什么会莫名其妙流鼻血| 笔触是什么意思| 蝎子的天敌是什么| 双肺上叶肺大泡是什么意思| 湿热内蕴吃什么中成药| 喉部有异物感是什么病| 阿斯伯格综合征是什么| 肌肉拉伤挂什么科| adidas是什么品牌| 脸长适合什么样的发型| 12点是什么时辰| 抢救失血伤员时要先采取什么措施| 75是什么意思| copd是什么病的简称| 天津卫的卫是什么意思| 切除甲状腺有什么影响| 欧巴是什么意思| 慈禧属什么生肖| 什么人会得胆囊炎| 不完全骨折是什么意思| 人造石是什么材料做的| 什么日子适合搬家| 夏至为什么吃馄饨| 维生素E什么牌子的效果最好| 身上起疙瘩是什么原因| 一个口一个犬读什么| 明月对什么| 蛇床子是什么| 11月26是什么星座| 什么都不是| 脱发严重应该去医院挂什么科| 巨石强森是什么人种| 空调什么度数最省电| 怀孕吃什么水果比较好| 松花粉对肝有什么好处| 草字头的字和什么有关| 造口是什么意思| 碗打碎了预示着什么| tin什么意思| 雾化治疗的作用是什么| 睡着了流口水是什么原因| 野生刺猬吃什么| 什么凌乱| 1968属什么生肖| 蜜蜂蜇人后为什么会死去| 考试为什么要用2b铅笔| 如来是什么意思| 脸上长癣是什么原因造成的| 哮喘什么症状| 胎毒是什么| 什么是抗生素类药物| 角瓜是什么| 左眼皮老是跳是什么原因| 肾不好有什么表现| 对什么有好处的英文| 结婚一年是什么婚| 为什么学习不好| 杨梅什么时候上市| 藿香泡水喝有什么好处| 猫来家里有什么预兆| 左后脑勺疼是什么原因| 排尿带血是什么原因| 多吃核桃有什么好处和坏处| 禅修是什么意思| 独宠是什么意思| 氨基酸什么牌子好| 五毒是什么| 人中深的女人代表什么| 被褥是什么| 朱元璋代表什么生肖| 鼻甲肥大是什么原因| 什么军官能天天回家住| 御风是什么意思| 性情什么意思| va是什么意思| 若无其事的若是什么意思| 日落是什么时辰| 咸鱼是什么意思| 休学需要什么条件| 下巴长痘痘什么原因| 书中自有颜如玉是什么意思| 什么照片看不出照的是谁| 黑裙子配什么鞋子| 窦性心律不齐是什么| 一什么绿毯| 卡介苗什么时候接种| 早日康复送什么花| 白羊座男生喜欢什么样的女生| 圻字五行属什么| 刘邦是什么星座| 包菜是什么菜| 白化病有什么危害吗| 琋字五行属什么| 吃什么对喉咙好| 白泽是什么| 女性白带有血丝是什么原因| 人走了说什么安慰的话| 喜欢紫色的人是什么性格| 木姜子什么味道| 为什么手臂上有很多很小的点| 脱肛和痔疮有什么区别| 一什么马车| 生肖牛和什么生肖最配| 尾盘跳水意味着什么| 性格好的女生是什么样| 10月10日是什么星座| 什么物流寄大件便宜| 咳嗽消炎药吃什么好| 大便呈绿色是什么原因| 为什么不要看电焊火花| 窝是什么结构的字| 菩提树是什么树| 尿喝起来是什么味道| 罗汉局是什么意思| 茶叶里面含有什么成分| 农历2月12日是什么星座| 泥灸是什么| 类风湿关节炎吃什么药效果好| 减肥什么时候喝牛奶| 毛主席女儿为什么姓李| 白蛇是什么蛇| 火为什么没有影子| 质粒是什么| 鹅和什么一起炖最好吃| 什么是情感障碍| 27岁属什么| 月经血是什么血| 梅毒是什么样的| 内疚是什么意思| 甲不开仓财物耗散是什么意思| 为什么榴莲那么贵| 今年天热的原因是什么| 小腿抽筋是什么原因引起的| 清对什么| 蜈蚣最怕什么药| pbg是什么意思| 梦见死人是什么意思| 空调睡眠是什么意思| 刚愎自负是什么意思| 龙眼有什么品种| 扁平疣是什么原因长出来的| 81是什么意思| 为什么喝纯牛奶会拉肚子| 甘胆酸是查什么的| 看头发应该挂什么科| 小舌头有什么用| gtp什么意思| 万圣节为什么要送糖果| beko是什么牌子| 邓绥和阴丽华什么关系| 豆浆不能和什么一起吃| 性质是什么| 为什么会做梦| sdeer是什么牌子| ards是什么病| 蚕丝衣服用什么洗最好| OD是什么| 手腕有痣代表什么| 脚上起水泡用什么药膏| 婴儿第一次发烧叫什么| 马甲是什么意思?| 吃秋葵有什么禁忌| 胃痛胃胀什么原因引起的| 送钱包的寓意是什么| 摆渡人是什么意思| 摘环后需要注意什么| 隙是什么意思| 为什么鱼和熊掌不可兼得| 阴囊潮湿吃什么| 45年属什么生肖| 十一月二十四是什么星座| 拯救银河系什么意思| 胃酸吃什么| 官官相护是什么意思| 妇科菌群失调吃什么药| 移徒什么意思| 阴阳两虚吃什么药| 险象环生是什么意思| 吃什么都吐是什么原因| 女m是什么意思| 喝咖啡有什么好处| 勃勃生机是什么意思| 美尼尔综合症吃什么药| 郡字五行属什么| 常吃阿司匹林有什么副作用| 口干舌燥什么原因| 春饼卷什么菜好吃| 咳嗽吐黄痰是什么原因| 非那根又叫什么| 惟妙惟肖什么意思| 眼泪为什么是咸的| 三界牌是什么| 百度

洗龙虾又被夹?苏宁洗碗机节的这款方太产品可以搞定

百度 目前,美国分娩镇痛率达到85%,英国达到90%,法国有的医院应用率达到96%。

In computing, a null pointer (sometimes shortened to nullptr or null) or null reference is a value saved for indicating that the pointer or reference does not refer to a valid object. Programs routinely use null pointers to represent conditions such as the end of a list of unknown length or the failure to perform some action; this use of null pointers can be compared to nullable types and to the Nothing value in an option type.

A null pointer should not be confused with an uninitialized pointer: a null pointer is guaranteed to compare unequal to any pointer that points to a valid object. However, in general, most languages do not offer such guarantee for uninitialized pointers. It might compare equal to other, valid pointers; or it might compare equal to null pointers. It might do both at different times; or the comparison might be undefined behavior. Also, in languages offering such support, the correct use depends on the individual experience of each developer and linter tools. Even when used properly, null pointers are semantically incomplete, since they do not offer the possibility to express the difference between "not applicable", "not known", and "future" values.[citation needed]

Because a null pointer does not point to a meaningful object, an attempt to access the data stored at that (invalid) memory location may cause a run-time error or immediate program crash. This is the null pointer error, or null pointer exception. It is one of the most common types of software weaknesses,[1] and Tony Hoare, who introduced the concept, has referred to it as a "billion dollar mistake".[2]

In C, two null pointers of any type are guaranteed to compare equal.[3] Prior to C23, the preprocessor macro NULL was provided, defined as an implementation-defined null pointer constant in <stdlib.h>,[4] which in C99 can be portably expressed with #define NULL ((void*)0), the integer value 0 converted to the type void* (see pointer to void type).[5] Since C23, a null pointer is represented with nullptr which is of type nullptr_t (first introduced to C++11), providing a type safe null pointer.[6]

The C standard does not say that the null pointer is the same as the pointer to memory address?0, though that may be the case in practice. Dereferencing a null pointer is undefined behavior in C,[7] and a conforming implementation is allowed to assume that any pointer that is dereferenced is not null.

In practice, dereferencing a null pointer may result in an attempted read or write from memory that is not mapped, triggering a segmentation fault or memory access violation. This may manifest itself as a program crash, or be transformed into a software exception that can be caught by program code. There are, however, certain circumstances where this is not the case. For example, in x86 real mode, the address 0000:0000 is readable and also usually writable, and dereferencing a pointer to that address is a perfectly valid but typically unwanted action that may lead to undefined but non-crashing behavior in the application; if a null pointer is represented as a pointer to that address, dereferencing it will lead to that behavior. There are occasions when dereferencing a pointer to address zero is intentional and well-defined; for example, BIOS code written in C for 16-bit real-mode x86 devices may write the interrupt descriptor table (IDT) at physical address?0 of the machine by dereferencing a pointer with the same value as a null pointer for writing. It is also possible for the compiler to optimize away the null pointer dereference, avoiding a segmentation fault but causing other undesired behavior.[8]

In C++, while the NULL macro was inherited from C, the integer literal for zero has been traditionally preferred to represent a null pointer constant.[9] However, C++11 introduced the explicit null pointer constant nullptr and type nullptr_t to be used instead, providing a type safe null pointer. nullptr and type nullptr_t were later introduced to C in C23.

Other languages

edit

In some programming language environments (at least one proprietary Lisp implementation, for example),[citation needed] the value used as the null pointer (called nil in Lisp) may actually be a pointer to a block of internal data useful to the implementation (but not explicitly reachable from user programs), thus allowing the same register to be used as a useful constant and a quick way of accessing implementation internals. This is known as the nil vector.

In languages with a tagged architecture, a possibly null pointer can be replaced with a tagged union which enforces explicit handling of the exceptional case; in fact, a possibly null pointer can be seen as a tagged pointer with a computed tag.

Programming languages use different literals for the null pointer. In Python, for example, a null value is called None. In Java and C#, the literal null is provided as a literal for reference types. In Pascal and Swift, a null pointer is called nil. In Eiffel, it is called a void reference. In Rust, the absence of a value is denoted as None, but a true null pointer is std::ptr::null().

Null dereferencing

edit

Because a null pointer does not point to a meaningful object, an attempt to dereference (i.e., access the data stored at that memory location) a null pointer usually (but not always) causes a run-time error or immediate program crash. MITRE lists the null pointer error as one of the most commonly exploited software weaknesses.[10]

  • In C, dereferencing a null pointer is undefined behavior.[7] Many implementations cause such code to result in the program being halted with an access violation, because the null pointer representation is chosen to be an address that is never allocated by the system for storing objects. However, this behavior is not universal. It is also not guaranteed, since compilers are permitted to optimize programs under the assumption that they are free of undefined behavior. This behaviour is the same in C++, as there is no null pointer exception in the C++ language. On platforms such as Unix-like systems and Windows with the Visual Studio compiler, an access violation causes a C/C++ SIGSEGV signal to be issued. Although in C/C++ null dereferences are not exceptions which can be caught in C++ try/catch blocks, it is possible to "catch" such an access violation by using (std::)signal() in C/C++ to specify a handler to be called when that signal is issued.
  • In D, much like C++, a null pointer dereference results in a segmentation fault.
  • In Delphi and many other Pascal implementations, the constant nil represents a null pointer to the first address in memory which is also used to initialize managed variables. Dereferencing it raises an external OS exception which is mapped onto a Pascal EAccessViolation exception instance if the System.SysUtils unit is linked in the uses clause.
  • In Java, access to a null reference (null) causes a NullPointerException (NPE), which can be caught by error handling code, but the preferred practice is to ensure that such exceptions never occur.
  • In Lisp, nil is a first class object. By convention, (first nil) is nil, as is (rest nil). So dereferencing nil in these contexts will not cause an error, but poorly written code can get into an infinite loop.
  • In .NET and C#, access to null reference (null) causes a NullReferenceException to be thrown. Although catching these is generally considered bad practice, this exception type can be caught and handled by the program.
  • In Objective-C, messages may be sent to a nil object (which is a null pointer) without causing the program to be interrupted; the message is simply ignored, and the return value (if any) is nil or 0, depending on the type.[11]
  • In Python, dereferencing None raises an AttributeError, as NoneType has no (user-facing) methods or attributes defined.
  • In Rust, dereferencing a null pointer (std::ptr::null()) in an unsafe block results in undefined behaviour, which usually results in a segmentation fault or corrupted memory.
  • Before the introduction of Supervisor Mode Access Prevention (SMAP), a null pointer dereference bug could be exploited by mapping page zero into the attacker's address space and hence causing the null pointer to point to that region. This could lead to code execution in some cases.[12]

Mitigation

edit

While there could be languages with no nulls, most do have the possibility of nulls so there are techniques to avoid or aid debugging null pointer dereferences.[13] Bond et al.[13] suggest modifying the Java Virtual Machine (JVM) to keep track of null propagation.

There are three levels of handling null references, in order of effectiveness:

  1. languages with no null;
  2. languages that can statically analyse code to avoid the possibility of null dereference at run time;
  3. if null dereference can occur at runtime, tools that aid debugging.

Pure functional languages are an example of level 1 since no direct access is provided to pointers and all code and data is immutable. User code running in interpreted or virtual-machine languages generally does not suffer the problem of null pointer dereferencing.[dubiousdiscuss]

Where a language does provide or utilise pointers which could become void, it is possible to avoid runtime null dereferences by providing compilation-time checking via static analysis or other techniques, with syntactic assistance from language features such as those seen in the Eiffel programming language with Void safety[14] to avoid null dereferences, D,[15] and Rust.[16]

In some languages analysis can be performed using external tools, but these are weak compared to direct language support with compiler checks since they are limited by the language definition itself.

The last resort of level 3 is when a null reference occurs at runtime, debugging aids can help.

History

edit

In 2009, Tony Hoare stated[2][17] [18] that he invented the null reference in 1965 as part of the ALGOL W language. In that 2009 reference Hoare describes his invention as a "billion-dollar mistake":

I call it my billion-dollar mistake. It was the invention of the null reference in 1965. At that time, I was designing the first comprehensive type system for references in an object oriented language (ALGOL W). My goal was to ensure that all use of references should be absolutely safe, with checking performed automatically by the compiler. But I couldn't resist the temptation to put in a null reference, simply because it was so easy to implement. This has led to innumerable errors, vulnerabilities, and system crashes, which have probably caused a billion dollars of pain and damage in the last forty years.

See also

edit

Notes

edit
  1. ^ "CWE-476: NULL Pointer Dereference". MITRE.
  2. ^ a b Tony Hoare (2025-08-14). "Null References: The Billion Dollar Mistake". InfoQ.com.
  3. ^ ISO/IEC 9899, clause 6.3.2.3, paragraph 4.
  4. ^ ISO/IEC 9899, clause 7.17, paragraph 3: NULL... which expands to an implementation-defined null pointer constant...
  5. ^ ISO/IEC 9899, clause 6.3.2.3, paragraph 3.
  6. ^ "WR14-N3042: Introduce the nullptr constant". open-std.org. 2025-08-14. Archived from the original on December 24, 2022.
  7. ^ a b ISO/IEC 9899, clause 6.5.3.2, paragraph 4, esp. footnote 87.
  8. ^ Lattner, Chris (2025-08-14). "What Every C Programmer Should Know About Undefined Behavior #1/3". blog.llvm.org. Archived from the original on 2025-08-14. Retrieved 2025-08-14.
  9. ^ Stroustrup, Bjarne (March 2001). "Chapter 5:
    The const qualifier (§5.4) prevents accidental redefinition of NULL and ensures that NULL can be used where a constant is required.". The C++ Programming Language (14th printing of 3rd?ed.). United States and Canada: Addison–Wesley. p.?88. ISBN?0-201-88954-4.
  10. ^ "CWE-476: NULL Pointer Dereference". MITRE.
  11. ^ The Objective-C 2.0 Programming Language, section "Sending Messages to nil".
  12. ^ "OS X exploitable kernel NULL pointer dereference in AppleGraphicsDeviceControl"
  13. ^ a b Bond, Michael D.; Nethercote, Nicholas; Kent, Stephen W.; Guyer, Samuel Z.; McKinley, Kathryn S. (2007). "Tracking bad apples". Proceedings of the 22nd annual ACM SIGPLAN conference on Object oriented programming systems and applications - OOPSLA '07. p.?405. doi:10.1145/1297027.1297057. ISBN?9781595937865. S2CID?2832749.
  14. ^ "Void-safety: Background, definition, and tools". Retrieved 2025-08-14.
  15. ^ Bartosz Milewski. "SafeD – D Programming Language". Retrieved 17 July 2014.
  16. ^ "Fearless Security: Memory Safety". Archived from the original on 8 November 2020. Retrieved 4 November 2020.
  17. ^ Tony Hoare (2025-08-14). "Presentation: "Null References: The Billion Dollar Mistake"". InfoQ.com.
  18. ^ Contieri, Maxi (2025-08-14). "Code Smell 304 - Null Pointer Exception". Maximiliano Contieri - Software Design. Retrieved 2025-08-14.

References

edit
  • Joint Technical Committee ISO/IEC JTC 1, Subcommittee SC 22, Working Group WG 14 (2025-08-14). International Standard ISO/IEC 9899 (PDF) (Committee Draft).{{cite book}}: CS1 maint: multiple names: authors list (link) CS1 maint: numeric names: authors list (link)
白癜风是什么 急支糖浆是什么梗 巨人观什么意思 便秘是什么 密送是什么意思
眉尾有痣代表什么 脸色苍白没有血色是什么原因 喝蜂蜜水不能吃什么 什么血型不招蚊子 反文旁和什么有关
九月十七日是什么星座 迅雷不及掩耳之势是什么意思 肺部钙化是什么意思啊 通班是什么意思 m2是什么单位
小人难防前一句是什么 小腿痛是什么原因 绿豆汤不能和什么一起吃 籍贯写什么 狗狗假孕是什么症状
罄竹难书是什么意思hcv7jop6ns1r.cn 喝碳酸饮料有什么危害qingzhougame.com 胡子长的快是什么原因hcv9jop1ns9r.cn 1987年属什么今年多大hcv9jop6ns5r.cn 一个歹一个殇读什么hcv8jop0ns5r.cn
狗叫是什么意思hcv7jop5ns3r.cn 海啸是什么hcv8jop5ns1r.cn b细胞淋巴肿瘤是一种什么病hcv9jop2ns9r.cn 肛门长肉球是什么原因hcv9jop5ns7r.cn 小鸡吃什么食物hcv9jop6ns2r.cn
老什么什么什么520myf.com 病案首页是什么hcv8jop2ns6r.cn 尿液臭味很重什么原因hcv8jop1ns0r.cn 拔牙后吃什么消炎药最好hcv8jop6ns8r.cn msms筛查是什么意思hcv8jop8ns7r.cn
上元节是什么节日hcv8jop5ns0r.cn 血压高吃什么药最好hcv8jop8ns7r.cn 拔罐黑紫色说明什么adwl56.com 睾丸炎吃什么药hcv9jop8ns1r.cn 温吞是什么意思hcv9jop3ns2r.cn
百度