{"id":34602,"date":"2022-01-03T14:38:55","date_gmt":"2022-01-03T19:38:55","guid":{"rendered":"https:\/\/mjtsai.com\/blog\/?p=34602"},"modified":"2022-01-03T14:38:55","modified_gmt":"2022-01-03T19:38:55","slug":"almost-always-unsigned","status":"publish","type":"post","link":"https:\/\/mjtsai.com\/blog\/2022\/01\/03\/almost-always-unsigned\/","title":{"rendered":"Almost Always Unsigned"},"content":{"rendered":"<p><a href=\"https:\/\/graphitemaster.github.io\/aau\/\">Dale Weiler<\/a> (via <a href=\"https:\/\/twitter.com\/richgel999\/status\/1477791905878528002\">Richard Geldreich<\/a>):<\/p>\n<blockquote cite=\"https:\/\/graphitemaster.github.io\/aau\/\">\n<p>There are a lot of arguments against the use of unsigned integers. Let me explain why I think they&rsquo;re mostly incorrect.<\/p>\n<p>[&#8230;]<\/p>\n<p>Trap representations are actually quite insufficient as they can only trigger at runtime when those paths are successfully executed with the correct trap-producing inputs. This coverage is impossible to expect in any non-trivial program even with exhaustive unit testing. The idea is also incompatible in many contexts such as library code where you almost never want the library to panic, but rather all errors be recoverable by the calling application code, or in service-availability sensitive code which must not be susceptible to denial of service attacks, where a panic is pretty much not acceptable.<\/p>\n<p>[&#8230;]<\/p>\n<p>The reality is that the use of signed and unsigned paints all your integers red\nor blue, respectively. \n  <a href=\"https:\/\/journal.stuffwithstuff.com\/2015\/02\/01\/what-color-is-your-function\/\">What color is Your Function<\/a>. The more of one you use, the more likely it is\neverything will also share the same signedness regardless of if it&rsquo;s appropriate.\nSince most integers never require representing negative values, I personally\nthink it&rsquo;s more appropriate to paint everything blue in this case.<\/p>\n<p>[&#8230;]<\/p>\n<p>In many ways signed integers are the null pointers of integers.<\/p>\n<\/blockquote>\n\n<p>Previously:<\/p>\n<ul>\n<li><a href=\"https:\/\/mjtsai.com\/blog\/2020\/05\/21\/remote-code-execution-in-qmail\/\">Remote Code Execution in qmail<\/a><\/li>\n<li><a href=\"https:\/\/mjtsai.com\/blog\/2014\/08\/24\/yet-another-integer-underflow-bug\/\">Yet Another Integer Underflow Bug<\/a><\/li>\n<\/ul>","protected":false},"excerpt":{"rendered":"<p>Dale Weiler (via Richard Geldreich): There are a lot of arguments against the use of unsigned integers. Let me explain why I think they&rsquo;re mostly incorrect. [&#8230;] Trap representations are actually quite insufficient as they can only trigger at runtime when those paths are successfully executed with the correct trap-producing inputs. This coverage is impossible [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"apple_news_api_created_at":"2022-01-03T19:38:57Z","apple_news_api_id":"e3c4e871-06d9-4bb5-82b3-8ea86e3ea0d7","apple_news_api_modified_at":"2022-01-03T19:38:57Z","apple_news_api_revision":"AAAAAAAAAAD\/\/\/\/\/\/\/\/\/\/w==","apple_news_api_share_url":"https:\/\/apple.news\/A48TocQbZS7WCs46obj6g1w","apple_news_coverimage":0,"apple_news_coverimage_caption":"","apple_news_is_hidden":false,"apple_news_is_paid":false,"apple_news_is_preview":false,"apple_news_is_sponsored":false,"apple_news_maturity_rating":"","apple_news_metadata":"\"\"","apple_news_pullquote":"","apple_news_pullquote_position":"","apple_news_slug":"","apple_news_sections":"\"\"","apple_news_suppress_video_url":false,"apple_news_use_image_component":false,"footnotes":""},"categories":[4],"tags":[45,326,259,71,982],"class_list":["post-34602","post","type-post","status-publish","format-standard","hentry","category-programming-category","tag-c","tag-c-plus-plus","tag-math","tag-programming","tag-underflow"],"apple_news_notices":[],"_links":{"self":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/34602","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/comments?post=34602"}],"version-history":[{"count":1,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/34602\/revisions"}],"predecessor-version":[{"id":34603,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/34602\/revisions\/34603"}],"wp:attachment":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/media?parent=34602"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/categories?post=34602"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/tags?post=34602"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}