{"action":"created","issue":{"url":"https://api.github.com/repos/Arondight/sudodev/issues/5","labels_url":"https://api.github.com/repos/Arondight/sudodev/issues/5/labels{/name}","comments_url":"https://api.github.com/repos/Arondight/sudodev/issues/5/comments","events_url":"https://api.github.com/repos/Arondight/sudodev/issues/5/events","html_url":"https://github.com/Arondight/sudodev/issues/5","id":115622105,"number":5,"title":"这是feature还是bug","user":{"login":"abbycin","id":6814167,"avatar_url":"https://avatars.githubusercontent.com/u/6814167?v=3","gravatar_id":"","url":"https://api.github.com/users/abbycin","html_url":"https://github.com/abbycin","followers_url":"https://api.github.com/users/abbycin/followers","following_url":"https://api.github.com/users/abbycin/following{/other_user}","gists_url":"https://api.github.com/users/abbycin/gists{/gist_id}","starred_url":"https://api.github.com/users/abbycin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/abbycin/subscriptions","organizations_url":"https://api.github.com/users/abbycin/orgs","repos_url":"https://api.github.com/users/abbycin/repos","events_url":"https://api.github.com/users/abbycin/events{/privacy}","received_events_url":"https://api.github.com/users/abbycin/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-11-07T01:17:50Z","updated_at":"2015-11-07T01:40:16Z","closed_at":null,"body":"我尝试用C++按照我的理解写一遍，发现我的是这样： \r\n按照uuid输出   \r\n```plain\r\n./a.out add\r\nScaning avaliable devices...\r\nThe following choices are avaliable\r\n[q]. quit\r\n[0]. 4E36250D3624F79B\r\n[1]. 9C941A5B941A37EA\r\n[2]. fd223770-d482-3d1e-9963-8e7e6c659a68\r\n[3]. 0229-150D\r\n[4]. 807ca61d-328c-3625-a54f-bb18bf62f086\r\nPlease enter a choice: q\r\n```\r\n按照分区输出   \r\n```plain\r\n./a.out add\r\nScaning avaliable devices...\r\nThe following choices are avaliable\r\n[q]. quit\r\n[0]. sda5\r\n[1]. sda4\r\n[2]. sda2\r\n[3]. sda1\r\n[4]. sda3\r\nPlease enter a choice: q\r\n```\r\n这两个输出是同一个设备。\r\n由于我的机器有两块硬盘，系统所在硬盘是`/dev/sdb` 所以通过fstab过滤后剩下的就是`/dev/sda`了。\r\n\r\n但是学姐的是这样：\r\n\r\n```plain\r\n./sudodev add\r\nuuid[0] = (null)\r\nuuid[1] = (null)\r\nuuid[2] = (null)\r\nuuid[3] = (null)\r\nuuid[4] = 4E36250D3624F79B\r\nuuid[5] = 9C941A5B941A37EA\r\nuuid[6] = fd223770-d482-3d1e-9963-8e7e6c659a68\r\nuuid[7] = 0229-150D\r\nuuid[8] = (null)\r\nuuid[9] = 807ca61d-328c-3625-a54f-bb18bf62f086\r\nuuid[10] = (null)\r\nNo available device found\r\nattempt failed\r\n```\r\n修改的代码, devs.c \r\n![modified1](http://128.199.117.18:30992/tmp/x.png)\r\n\r\n上面输出的`(null)`就是已经过滤掉的`/dev/sdbx`, 但是在sudodev.c里面，有这样的代码\r\n```c\r\nfor (index = 0; list[index]; ++index);\r\n  devicesLen = index;\r\n\r\n  if (!(devices = (device_t **)malloc ((devicesLen + 1) * sizeof (device_t *))))\r\n    {\r\n      say (mode, MSG_E, \"malloc failed: %s\\n\", strerror (errno));\r\n      abort ();\r\n    }\r\n  memset (devices, 0, (devicesLen + 1) * sizeof (device_t *));\r\n\r\n  for (index = 0, count = 0; list[index]; ++index)\r\n    {\r\n      snprintf (path, MAXPATHLEN, \"%s/%s\", interface, list[index]);\r\n\r\n    ...\r\n```\r\n这个文件中的`count` 没有初始化， 在以上for()中自加，但是由于`list[index]`为null不会进入循环\r\n![modified2](http://128.199.117.18:30992/tmp/x1.png) \r\n\r\n**所以，学姐， 这是feature还是bug啊？ 另外的那块硬盘算是外部设备吗？**\r\n"},"comment":{"url":"https://api.github.com/repos/Arondight/sudodev/issues/comments/154596231","html_url":"https://github.com/Arondight/sudodev/issues/5#issuecomment-154596231","issue_url":"https://api.github.com/repos/Arondight/sudodev/issues/5","id":154596231,"user":{"login":"Arondight","id":13673702,"avatar_url":"https://avatars.githubusercontent.com/u/13673702?v=3","gravatar_id":"","url":"https://api.github.com/users/Arondight","html_url":"https://github.com/Arondight","followers_url":"https://api.github.com/users/Arondight/followers","following_url":"https://api.github.com/users/Arondight/following{/other_user}","gists_url":"https://api.github.com/users/Arondight/gists{/gist_id}","starred_url":"https://api.github.com/users/Arondight/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Arondight/subscriptions","organizations_url":"https://api.github.com/users/Arondight/orgs","repos_url":"https://api.github.com/users/Arondight/repos","events_url":"https://api.github.com/users/Arondight/events{/privacy}","received_events_url":"https://api.github.com/users/Arondight/received_events","type":"User","site_admin":false},"created_at":"2015-11-07T01:40:16Z","updated_at":"2015-11-07T01:40:16Z","body":"艾玛，我还抱着手机钻被窝里聊QQ 呢(ฅ>ω<*ฅ)\r\n这是一个bug，因为代码是下班以后追完新番写的，所以写的时候已经忘掉之前的想法了，顺着那个dev 点c 的代码往上看，会看到设备不存在于fstab 时会直接continue，但是再对比上面第一个continue 的情况，会发现这里新加的代码少了计数器的自减操作。从设计上来说是绝对不会出现null 在有效设备之前的情况，不过实现的时候因为计数器一直自增，所以出现了事与愿违的空指针。\r\nbug 的原因感觉应该就是这样，如果楼主方便的话帮我发个pull request 吧，commit 里面链接一下这个issue，暖气的力量太强大实在起不来了(ฅ>ω<*ฅ)"}}