Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit cf03193

Browse files
committed
Implemented PyMac_GetFullPathname for MacPython.
1 parent 78e0fc7 commit cf03193

1 file changed

Lines changed: 13 additions & 3 deletions

File tree

Mac/Python/macglue.c

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ get_folder_parent (FSSpec * fss, FSSpec * parent)
203203
/* Given an FSSpec return a full, colon-separated pathname */
204204

205205
OSErr
206-
PyMac_GetFullPath (FSSpec *fss, char *buf)
206+
PyMac_GetFullPathname (FSSpec *fss, char *buf, int length)
207207
{
208208
short err;
209209
FSSpec fss_parent, fss_current;
@@ -212,6 +212,10 @@ PyMac_GetFullPath (FSSpec *fss, char *buf)
212212

213213
fss_current = *fss;
214214
plen = fss_current.name[0];
215+
if ( plen+2 > length ) {
216+
*buf = 0;
217+
return errFSNameTooLong;
218+
}
215219
memcpy(buf, &fss_current.name[1], plen);
216220
buf[plen] = 0;
217221
/* Special case for disk names */
@@ -222,19 +226,25 @@ PyMac_GetFullPath (FSSpec *fss, char *buf)
222226
}
223227
while (fss_current.parID > 1) {
224228
/* Get parent folder name */
225-
if (err = get_folder_parent(&fss_current, &fss_parent))
229+
if (err = get_folder_parent(&fss_current, &fss_parent)) {
230+
*buf = 0;
226231
return err;
232+
}
227233
fss_current = fss_parent;
228234
/* Prepend path component just found to buf */
229235
plen = fss_current.name[0];
230236
if (strlen(buf) + plen + 1 > 1024) {
231237
/* Oops... Not enough space (shouldn't happen) */
232238
*buf = 0;
233-
return -1;
239+
return errFSNameTooLong;
234240
}
235241
memcpy(tmpbuf, &fss_current.name[1], plen);
236242
tmpbuf[plen] = ':';
237243
strcpy(&tmpbuf[plen+1], buf);
244+
if ( strlen(tmpbuf) > length ) {
245+
*buf = 0;
246+
return errFSNameTooLong;
247+
}
238248
strcpy(buf, tmpbuf);
239249
}
240250
return 0;

0 commit comments

Comments
 (0)