三月生日是什么星座| 大胯疼是什么原因引起| 抽脂手术对身体有什么副作用| 老来得子是什么意思| 梦见情人是什么意思啊| 土字旁的字与什么有关| o型血生的孩子是什么血型| 冰心原名是什么| 什么样的刘胡兰| 锴字五行属什么| 痰多是什么原因造成的| 食物不耐受是什么意思| 喝中药可以吃什么水果| 什么店可以买到老鼠药| 吃土豆有什么好处和坏处| 什么是一线城市| 口腔溃疡喝什么水| 圣水是什么| 林子祥属什么生肖| e抗原阳性是什么意思| 巡视员什么级别| 闰6月是什么意思| 七月二十二什么日子| spo2过低是什么意思| 2016年属什么| 98年属什么的| 益生菌适合什么人群吃| 南京有什么好玩的地方| 条件兵是什么意思| 花甲之年是什么意思| 胎盘分级0级什么意思| 宅心仁厚是什么意思| 梦到数钱代表什么预兆| 秒了是什么意思| 猴魁属于什么茶| 红枣桂圆泡水喝有什么好处和坏处| 亚五行属什么| 号是什么| 旅拍什么意思| 尿血是什么症状| 合拢是什么意思| 北京有什么好玩的地方| 开光什么意思| 坐骨神经吃什么药| 甲亢多吃什么食物比较好| 白细胞高是什么意思| 胰腺炎可以吃什么| 血尿是什么颜色| 310什么意思| 抖是什么生肖| 临界心电图是什么意思| 喊6个1是什么意思| 04属什么生肖| 播客是什么意思| 过敏去医院挂什么科| 发票抬头是什么| 梅毒螺旋体抗体阳性是什么意思| 整天想睡觉是什么原因| 小孩突然头疼是什么原因| 中国的全称是什么| 混圈是什么意思| 梦见老公不理我是什么意思| 珠地棉是什么面料| acs是什么病| 减肥吃什么水果好| 煞科什么意思| 脚底干裂起硬皮是什么原因怎么治| 10月28是什么星座| 参事是什么级别| 一什么土| 山竹什么时候吃是应季| 什么是霉菌| 猫咪呕吐吃什么药| 汗青是什么意思| 癫是什么意思| hay什么意思| 梦见老公出轨什么意思| 为什么不建议年轻人做肠镜| 辟支佛是什么意思| 这是什么踏板| 痰多是什么问题| 四点底与什么有关| 老年性阴道炎用什么药| 什么是流水| 无产阶级是什么意思| 酸碱度偏低是什么原因| 海娜是什么| 脚踝发黑是什么原因| 小分子水是什么水| cb是什么| 怕冷的女人是什么原因| 鼻子突然流血是什么原因| 遗精是什么原因| 版图是什么意思| 七点半是什么时辰| 2006属狗的五行缺什么| 77岁属什么生肖| 512是什么节日| 为什么都说头胎很重要| 2月1日是什么星座| 孤独终老什么意思| 停车坐爱枫林晚的坐是什么意思| 男士175是什么码| 卒中什么意思| 哺乳期吃什么下奶| 碳水化合物是什么食物| 乳房硬块疼是什么原因| 立秋当天吃什么| 解脲支原体是什么| 2024年属什么年| 经常耳鸣是什么原因引起的| 滴虫性阴道炎用什么药好| 白陶土样便见于什么病| 眉毛上长痘是什么原因| 垂线是什么| 五十岁是什么之年| 田七蒸瘦肉有什么功效| 梦见自己拉了好多屎是什么意思| 岫玉是什么玉| 宝宝拉黑色大便是什么原因| 被蜜蜂蛰了擦什么药| 吃什么对喉咙好| 惆怅是什么意思| ktv是什么意思| 浪琴表属于什么档次| 心博是什么意思| 歧视是什么意思| 大人吃什么排黄疸快| 喝胶原蛋白肽有什么好处| 棉花代表什么生肖| 狂犬疫苗什么时候打| 想一出是一出什么意思| 防晒隔离什么牌子好| 人为什么会得白血病| qd是什么意思| 藜麦是什么东西| 入户口需要什么资料| 胃阳虚吃什么中成药| 怀孕初期不能吃什么| 主管是什么级别| mup是什么意思| 去医院看脚挂什么科| 独角仙吃什么食物| 路虎为什么叫奇瑞路虎| 为什么会长生长纹| 讨吃货什么意思| 谷草转氨酶偏低是什么原因| 糖宝是什么虫| 甘油脂肪酸酯是什么| 日加华读什么| 琛字五行属什么| 打哈哈是什么意思| 青椒炒什么好吃又简单| 眼花是什么原因引起的| 51岁属什么生肖| 羽军念什么| 人工肝是什么意思| 嘴咸是什么原因| 肉刺长什么样子图片| 1980年是什么年| cn是什么单位| 96是什么意思| 避孕药什么时候吃有效| 肠胃不好吃什么水果比较好| 家里有蜈蚣是什么原因| 拉红尿是什么原因| 什么样的池塘| 劳模是什么意思| 17点到19点是什么时辰| 孕妇c反应蛋白高说明什么| 养神经吃什么食物最好| 1993属什么生肖| 为什么女生| 自律什么意思| 腰果不能和什么一起吃| 黄酮是什么| 散佚是什么意思| 停诊是什么意思| 七年是什么婚| 带状疱疹看什么科| 高压高低压正常是什么原因| 脑白质变性什么意思| 跨界是什么意思| ace是什么意思| 凌字五行属什么| 扭伤挂什么科| 贸易壁垒是什么意思| 不忘初心方得始终是什么意思| 吃什么可以减肥肚子| 为什么大姨妈迟迟不来| 美纹纸是干什么用的| 孩子容易出汗是什么原因| 彩超检查什么| 脑梗什么症状| 怀孕分泌物是什么颜色| feat什么意思| 军校毕业是什么军衔| 罗衣是什么意思| 尿频尿多是什么原因| 鱼休子是什么| 温度计里面红色液体是什么| 沉疴是什么意思| 炒菜用什么锅最好| 你的名字讲的什么故事| 为什么睡久了会头疼| 什么是ci| 百合和拉拉有什么区别| 补硒有什么好处| 尿道口流白色液体是什么病| 任性什么意思| 65年属什么| 以马内利什么意思| 商朝后面是什么朝代| 副连长是什么军衔| hrd是什么意思| 京东自营店是什么意思| 河北有什么山| 心机重的人弱点是什么| 为什么喉咙痛| 口腔溃疡反反复复是什么原因| 来大姨妈能吃什么水果| 什么星座颜值最高| 米诺地尔有什么副作用| 疱疹是什么症状| 鸿雁是什么意思| 切痣挂什么科| 乳房边缘疼是什么原因| 黄铜刮痧板有什么好处| 舌头干燥是什么原因| 四月七号是什么星座| 什么叫血沉| 扁平足适合穿什么鞋| 2月是什么星座| 文曲星什么意思| 罗贯中和施耐庵是什么关系| 菩提子是什么材质| 马齿苋煮水喝有什么功效| 现在做什么最赚钱| 北洋军阀是什么意思| 梦见跟妈妈吵架是什么意思| 脾虚湿热吃什么药| 碧玺是什么意思| 阴道口疼是什么原因| 抚今追昔的意思是什么| 金银花洗澡对婴儿有什么好处| 淞字五行属什么| 腰痛吃什么好| 身份证带x是什么意思| 狗狗吃南瓜有什么好处| 绿豆的功效与作用是什么| 梦见长大水是什么意思| 意向是什么意思| 瓒字取名有什么寓意| 劣迹斑斑是什么意思| 二氧化碳分压高说明什么| hpv什么病毒| 猫吃什么食物| 益生菌什么牌子最好| 牛肉用什么炒好吃| 包饺子用什么面粉| 97年属什么的生肖| 缺乏维生素b12的症状是什么| 火车为什么会晚点| 机关单位和事业单位有什么区别| 百度Jump to content

日本防相视察自卫队直升机事故现场 向民众致歉

From Wikipedia, the free encyclopedia
百度 1927年3月在北伐的国民革命军临近上海的情况下,领导上海工人第三次武装起义,赶走了驻守上海的北洋军阀部队。

In computer programming, a null-terminated string is a character string stored as an array containing the characters and terminated with a null character (a character with an internal value of zero, called "NUL" in this article, not same as the glyph zero). Alternative names are C string, which refers to the C programming language and ASCIIZ[1] (although C can use encodings other than ASCII).

The length of a string is found by searching for the (first) NUL. This can be slow as it takes O(n) (linear time) with respect to the string length. It also means that a string cannot contain a NUL (there is a NUL in memory, but it is after the last character, not in the string).

History

[edit]

Null-terminated strings were produced by the .ASCIZ directive of the PDP-11 assembly languages and the ASCIZ directive of the MACRO-10 macro assembly language for the PDP-10. These predate the development of the C programming language, but other forms of strings were often used.

At the time C (and the languages that it was derived from) was developed, memory was extremely limited, so using only one byte of overhead to store the length of a string was attractive. The only popular alternative at that time, usually called a "Pascal string" (a more modern term is "length-prefixed"), used a leading byte to store the length of the string. This allows the string to contain NUL and made finding the length need only one memory access (O(1) (constant) time), but limited string length to 255 characters. C designer Dennis Ritchie chose to follow the convention of null-termination to avoid the limitation on the length of a string and because maintaining the count seemed, in his experience, less convenient than using a terminator.[2]

This had some influence on CPU instruction set design. Some CPUs in the 1970s and 1980s, such as the Zilog Z80 and the DEC VAX, had dedicated instructions for handling length-prefixed strings. However, as the null-terminated string gained traction, CPU designers began to take it into account, as seen for example in IBM's decision to add the "Logical String Assist" instructions to the ES/9000 520 in 1992 and the vector string instructions to the IBM z13 in 2015.[3]

FreeBSD developer Poul-Henning Kamp, writing in ACM Queue, referred to the victory of null-terminated strings over a 2-byte (not one-byte) length as "the most expensive one-byte mistake" ever.[4]

Limitations

[edit]

While simple to implement, this representation has been prone to errors and performance problems.

Null-termination has historically created security problems.[5] A NUL inserted into the middle of a string will truncate it unexpectedly.[6] A common bug was to not allocate the additional space for the NUL, so it was written over adjacent memory. Another was to not write the NUL at all, which was often not detected during testing because the block of memory already contained zeros. Due to the expense of finding the length, many programs did not bother before copying a string to a fixed-size buffer, causing a buffer overflow if it was too long.

The inability to store a zero requires that text and binary data be kept distinct and handled by different functions (with the latter requiring the length of the data to also be supplied). This can lead to code redundancy and errors when the wrong function is used.

The speed problems with finding the length can usually be mitigated by combining it with another operation that is O(n) anyway, such as in strlcpy. However, this does not always result in an intuitive API.

Character encodings

[edit]

Null-terminated strings require that the encoding does not use a zero byte (0x00) anywhere; therefore it is not possible to store every possible ASCII or UTF-8 string.[7][8][9] However, it is common to store the subset of ASCII or UTF-8 – every character except NUL – in null-terminated strings. Some systems use "modified UTF-8" which encodes NUL as two non-zero bytes (0xC0, 0x80) and thus allow all possible strings to be stored. This is not allowed by the UTF-8 standard, because it is an overlong encoding, and it is seen as a security risk. Some other byte may be used as end of string instead, like 0xFE or 0xFF, which are not used in UTF-8.

UTF-16 uses 2-byte integers and as either byte may be zero (and in fact every other byte is, when representing ASCII text), cannot be stored in a null-terminated byte string. However, some languages implement a string of 16-bit UTF-16 characters, terminated by a 16-bit NUL (0x0000).

Improvements

[edit]

Many attempts to make C string handling less error prone have been made. One strategy is to add safer functions such as strdup and strlcpy, whilst deprecating the use of unsafe functions such as gets. Another is to add an object-oriented wrapper around C strings so that only safe calls can be done. However, it is possible to call the unsafe functions anyway.

Most modern libraries replace C strings with a structure containing a 32-bit or larger length value (far more than were ever considered for length-prefixed strings), and often add another pointer, a reference count, and even a NUL to speed up conversion back to a C string. Memory is far larger now, such that if the addition of 3 (or 16, or more) bytes to each string is a real problem the software will have to be dealing with so many small strings that some other storage method will save even more memory (for instance there may be so many duplicates that a hash table will use less memory). Examples include the C++ Standard Template Library std::string, the Qt QString, the MFC CString, and the C-based implementation CFString from Core Foundation as well as its Objective-C sibling NSString from Foundation, both by Apple. More complex structures may also be used to store strings such as the rope.

See also

[edit]

References

[edit]
  1. ^ "Chapter 15 - MIPS Assembly Language" (PDF). Carleton University. Retrieved 9 October 2023.
  2. ^ Ritchie, Dennis M. (1996). "The development of the C language". In Bergin, Jr., Thomas J.; Gibson, Jr., Richard G. (eds.). History of Programming Languages (2 ed.). New York: ACM Press. ISBN 0-201-89502-1 – via Addison-Wesley (Reading, Mass).
  3. ^ IBM z/Architecture Principles of Operation
  4. ^ Kamp, Poul-Henning (25 July 2011), "The Most Expensive One-byte Mistake", ACM Queue, 9 (7): 40–43, doi:10.1145/2001562.2010365, ISSN 1542-7730, S2CID 30282393
  5. ^ Rain Forest Puppy (9 September 1999). "Perl CGI problems". Phrack Magazine. 9 (55). artofhacking.com: 7. Retrieved 3 January 2016.
  6. ^ "Null byte injection on PHP?".
  7. ^ Yergeau, Fran?ois (November 2003). "UTF-8, a transformation format of ISO 10646". Retrieved 19 September 2013.
  8. ^ "Unicode/UTF-8-character table". Retrieved 13 September 2013.
  9. ^ Kuhn, Markus. "UTF-8 and Unicode FAQ". Retrieved 13 September 2013.
吃什么去肝火最快 宰相肚里能撑船是什么意思 中暑头晕吃什么药 异国他乡的意思是什么 疱疹什么症状
横死是什么意思 胎儿停止发育是什么原因造成的 为什么晚上不能晾衣服 盆腔炎吃什么药 秫米是什么米
草莓印是什么意思 桃子是什么形状 平均血小板体积偏低是什么原因 绿茶喝多了有什么危害 老是打嗝是什么病的征兆
235是什么意思 为什么长火疖子 什么是假性抑郁症 小猫什么时候断奶 醋泡葡萄干有什么功效和作用
九寨沟在四川什么地方wzqsfys.com 排尿困难吃什么药hcv8jop3ns7r.cn 孕妇梦见好多蛇是什么预兆hcv9jop4ns8r.cn 婴儿肥是什么意思zsyouku.com 灰色裤子配什么上衣好看hcv9jop3ns4r.cn
普洱茶有什么功效与作用hcv7jop7ns0r.cn 建档需要准备什么资料hcv8jop6ns1r.cn 什么叫克隆hcv8jop9ns8r.cn 两个土念什么hcv9jop7ns4r.cn 马弁是什么意思hcv8jop1ns7r.cn
荸荠读音是什么hcv8jop8ns1r.cn 手腕血管疼是什么原因hcv8jop2ns4r.cn 44是什么意思hcv9jop5ns7r.cn 是什么原因导致肥胖hcv8jop9ns7r.cn 好吃懒做的动物是什么生肖hcv9jop8ns3r.cn
柳字五行属什么hcv9jop5ns1r.cn 羊冲什么生肖hcv7jop9ns8r.cn 草字头下面一个高字读什么hcv8jop4ns9r.cn 追忆是什么意思hcv8jop1ns7r.cn 为什么手会脱皮mmeoe.com
百度