Mercurial > hg > mercurial-crew-with-dirclash
comparison mercurial/osutil.c @ 5422:a3ba7ef98c94
osutil: eliminate alloca call
- make full_path a PATH_MAX + epsilon local buffer
- use strncpy and strncat
author | Matt Mackall <mpm@selenic.com> |
---|---|
date | Mon, 08 Oct 2007 18:47:12 -0500 |
parents | 9b5d626be8ba |
children | e5f238a8b0d2 |
comparison
equal
deleted
inserted
replaced
5421:9b5d626be8ba | 5422:a3ba7ef98c94 |
---|---|
116 DIR *dir = NULL; | 116 DIR *dir = NULL; |
117 struct dirent *ent; | 117 struct dirent *ent; |
118 PyObject *list = NULL; | 118 PyObject *list = NULL; |
119 PyObject *ctor_args = NULL; | 119 PyObject *ctor_args = NULL; |
120 int all_kinds = 1; | 120 int all_kinds = 1; |
121 char *full_path; | 121 char full_path[PATH_MAX + 10]; |
122 int path_len; | 122 int path_len; |
123 int do_stat; | 123 int do_stat; |
124 char *path; | 124 char *path; |
125 int ret; | 125 int ret; |
126 ssize_t size; | 126 ssize_t size; |
141 | 141 |
142 list = PyList_New(0); | 142 list = PyList_New(0); |
143 if (!list) | 143 if (!list) |
144 goto bail; | 144 goto bail; |
145 | 145 |
146 full_path = alloca(path_len + PATH_MAX + 2); | 146 strncpy(full_path, path, PATH_MAX); |
147 memcpy(full_path, path, path_len); | |
148 full_path[path_len] = '/'; | 147 full_path[path_len] = '/'; |
149 | 148 |
150 for (ent = readdir(dir); ent; ent = readdir(dir)) { | 149 for (ent = readdir(dir); ent; ent = readdir(dir)) { |
151 PyObject *name = NULL; | 150 PyObject *name = NULL; |
152 PyObject *py_kind = NULL; | 151 PyObject *py_kind = NULL; |
227 kind = py_kind == Py_None ? -1 : PyInt_AsLong(py_kind); | 226 kind = py_kind == Py_None ? -1 : PyInt_AsLong(py_kind); |
228 | 227 |
229 if (kind != -1 && !do_stat) | 228 if (kind != -1 && !do_stat) |
230 continue; | 229 continue; |
231 | 230 |
232 strcpy(full_path + path_len + 1, name); | 231 strncat(full_path + path_len + 1, name, |
232 PATH_MAX - path_len); | |
233 full_path[PATH_MAX] = 0; | |
233 | 234 |
234 if (do_stat) { | 235 if (do_stat) { |
235 struct listdir_stat *st; | 236 struct listdir_stat *st; |
236 | 237 |
237 if (!ctor_args) { | 238 if (!ctor_args) { |