{"action":"created","issue":{"url":"https://api.github.com/repos/BIC-MNI/libminc/issues/36","labels_url":"https://api.github.com/repos/BIC-MNI/libminc/issues/36/labels{/name}","comments_url":"https://api.github.com/repos/BIC-MNI/libminc/issues/36/comments","events_url":"https://api.github.com/repos/BIC-MNI/libminc/issues/36/events","html_url":"https://github.com/BIC-MNI/libminc/issues/36","id":89345395,"number":36,"title":"Undefined behaviour caught by UBSan in \"minc2-hyper-test-2\" test","user":{"login":"seanm","id":117260,"avatar_url":"https://avatars.githubusercontent.com/u/117260?v=3","gravatar_id":"","url":"https://api.github.com/users/seanm","html_url":"https://github.com/seanm","followers_url":"https://api.github.com/users/seanm/followers","following_url":"https://api.github.com/users/seanm/following{/other_user}","gists_url":"https://api.github.com/users/seanm/gists{/gist_id}","starred_url":"https://api.github.com/users/seanm/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/seanm/subscriptions","organizations_url":"https://api.github.com/users/seanm/orgs","repos_url":"https://api.github.com/users/seanm/repos","events_url":"https://api.github.com/users/seanm/events{/privacy}","received_events_url":"https://api.github.com/users/seanm/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":3,"created_at":"2015-06-18T17:04:55Z","updated_at":"2015-06-18T17:35:13Z","closed_at":null,"body":"UBSan finds only one test failure (nice!):\r\n\r\nThe test \"minc2-hyper-test-2\" has this loop:\r\n```\r\n   59  \t  for ( i = 0; i < CZ * CY * CX; i++ ) {\r\n-> 60  \t    buf[i] = ( unsigned short ) (i * 0.01);\r\n   61  \t  }\r\n```\r\n\r\nAlso note:\r\n```\r\n#define CZ 142\r\n#define CY 245\r\n#define CX 210\r\n```\r\n\r\nThus the loop runs 7 305 900 times, which even after dividing by 100 gives numbers too big to fit in an unsigned 16 bit number and UBSan warns:\r\n\r\n```\r\n41: (/Users/builder/external/libminc-clang-dbg-x86_64-static/testdir/minc2-hyper-test-2+0x100004e36): runtime error: value 65536 is outside the range of representable values of type 'unsigned short'\r\n```\r\n\r\nDoes the buffer contents matter much?  If I divide by 1000 instead the test passed and the warning is gone."},"comment":{"url":"https://api.github.com/repos/BIC-MNI/libminc/issues/comments/113230026","html_url":"https://github.com/BIC-MNI/libminc/issues/36#issuecomment-113230026","issue_url":"https://api.github.com/repos/BIC-MNI/libminc/issues/36","id":113230026,"user":{"login":"rdvincent","id":1395526,"avatar_url":"https://avatars.githubusercontent.com/u/1395526?v=3","gravatar_id":"","url":"https://api.github.com/users/rdvincent","html_url":"https://github.com/rdvincent","followers_url":"https://api.github.com/users/rdvincent/followers","following_url":"https://api.github.com/users/rdvincent/following{/other_user}","gists_url":"https://api.github.com/users/rdvincent/gists{/gist_id}","starred_url":"https://api.github.com/users/rdvincent/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rdvincent/subscriptions","organizations_url":"https://api.github.com/users/rdvincent/orgs","repos_url":"https://api.github.com/users/rdvincent/repos","events_url":"https://api.github.com/users/rdvincent/events{/privacy}","received_events_url":"https://api.github.com/users/rdvincent/received_events","type":"User","site_admin":false},"created_at":"2015-06-18T17:35:13Z","updated_at":"2015-06-18T17:35:13Z","body":"Yes."}}