{"action":"closed","issue":{"url":"https://api.github.com/repos/waneck/systools/issues/19","labels_url":"https://api.github.com/repos/waneck/systools/issues/19/labels{/name}","comments_url":"https://api.github.com/repos/waneck/systools/issues/19/comments","events_url":"https://api.github.com/repos/waneck/systools/issues/19/events","html_url":"https://github.com/waneck/systools/issues/19","id":54167901,"number":19,"title":"openFile: when multi is false, the path returned end with extra \"/\" (Win)","user":{"login":"guoboism","id":705499,"avatar_url":"https://avatars.githubusercontent.com/u/705499?v=3","gravatar_id":"","url":"https://api.github.com/users/guoboism","html_url":"https://github.com/guoboism","followers_url":"https://api.github.com/users/guoboism/followers","following_url":"https://api.github.com/users/guoboism/following{/other_user}","gists_url":"https://api.github.com/users/guoboism/gists{/gist_id}","starred_url":"https://api.github.com/users/guoboism/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/guoboism/subscriptions","organizations_url":"https://api.github.com/users/guoboism/orgs","repos_url":"https://api.github.com/users/guoboism/repos","events_url":"https://api.github.com/users/guoboism/events{/privacy}","received_events_url":"https://api.github.com/users/guoboism/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/waneck/systools/labels/pr-welcome","name":"pr-welcome","color":"bfe5bf"}],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2015-01-13T09:31:03Z","updated_at":"2015-01-27T16:23:55Z","closed_at":"2015-01-27T16:23:55Z","body":"Hi,\r\n\r\nThere is a bug about the newly committed \"multi\" option to the OpenFileDialog. On windows(of course), when multi is false, openFile will return a string ending with extra \"/\", like \"C:/folder/file.txt/\".\r\n\r\nI checked the code and did experiments and notice 2 things:\r\n\r\n1 systools_dialogs_open_file() in project/src/win/dialogs.c rely on the value of extra char after normal ending \\0\r\n\r\n```\r\nif (GetOpenFileName(&ofn)) {\t\t\r\n\t\tchar* file = ofn.lpstrFile;\r\n\t\tchar* folder = NULL;\r\n\t\tlong pass = 1;\r\n\t\twhile(*file!=0) {\r\n\t\t\tsize_t len = strlen(file);\t\t\t\r\n\t\t\tlen++;\r\n\t\t\tif (pass==1) {\r\n\t\t\t\tr->strings = realloc(r->strings,sizeof(char*)*(r->count+1));\r\n\t\t\t\tr->strings[r->count] = strdup(file);\r\n\t\t\t\tfolder = file;\t\t\t\r\n\t\t\t\tr->count++;\r\n\t\t\t} else if (pass==2) {\r\n\t\t\t\tr->strings[0] = realloc(r->strings[0],strlen(r->strings[0])+strlen(file)+2);\r\n\t\t\t\tstrcat(r->strings[0], \"\\\\\");\r\n\t\t\t\tstrcat(r->strings[0], file);\t\t\t\t\t\t\t\t\r\n\t\t\t} else {\r\n\t\t\t\tr->strings = realloc(r->strings,sizeof(char*)*(r->count+1));\r\n\t\t\t\tr->strings[r->count] = malloc(strlen(folder)+strlen(file)+2);\r\n\t\t\t\tstrcpy(r->strings[r->count], folder);\r\n\t\t\t\tstrcat(r->strings[r->count], \"\\\\\");\r\n\t\t\t\tstrcat(r->strings[r->count], file);\r\n\t\t\t\tr->count++;\r\n\t\t\t}\r\n\t\t\tfile += len;\r\n\t\t\tpass++;\t\t\r\n\t\t}\t\t\r\n\t}\t\r\n```\r\nOn second loop, file would be ofn.lpstrFile + strlen(ofn.lpstrFile)+1\r\n\r\n2 Windows return different things by GetOpenFileName(): (0 stands for \\0; * for random value)\r\n\r\n   With OFN_ALLOWMULTISELECT, when selecting 2 or more files, lpstrFile would be: path0fileA0fileB00\r\n\r\nWith OFN_ALLOWMULTISELECT, when selecting 1 file, lpstrFile  would be pathfileA00\r\n\r\n(Windows somehow make sure there are two \\0 at the end and code works well)\r\n\r\nWithout OFN_ALLOWMULTISELECT, lpstrFile  would be pathfileA0*, and it will go into pass2, and have extra \"/\" added\r\n\r\n\r\nSolution: memset 0 for malloc-ed ofn.lpstrFile (Line 98)\r\n\r\n```\r\nofn.lpstrFile = malloc(8192);\r\nmemset(ofn.lpstrFile, 0 , 8192);\r\n```\r\n\r\n\r\n\r\n"}}