comparison src/fileio.c @ 851:e7ee5f8bde58

[xemacs-hg @ 2002-05-23 11:46:08 by ben] fix for raymond toy's crash, alloca crashes, some recover-session improvements files.el: Recover-session improvements: Only show session files where some files can actually be recovered, and show in chronological order. subr.el, menubar-items.el: As promised to rms, the functionality in truncate-string-with-continuation-dots has been merged into truncate-string-to-width. Change callers in menubar-items.el. select.el: Document some of these funs better. Fix problem where we were doing own-clipboard twice. Makefile.in.in: Add alloca.o. Ensure that alloca.s doesn't compile into alloca.o, but allocax.o (not that it's currently used or anything.) EmacsFrame.c, abbrev.c, alloc.c, alloca.c, callint.c, callproc.c, config.h.in, device-msw.c, device-x.c, dired.c, doc.c, editfns.c, emacs.c, emodules.c, eval.c, event-Xt.c, event-msw.c, event-stream.c, file-coding.c, fileio.c, filelock.c, fns.c, glyphs-gtk.c, glyphs-msw.c, glyphs-x.c, gui-x.c, input-method-xlib.c, intl-win32.c, lisp.h, lread.c, menubar-gtk.c, menubar-msw.c, menubar.c, mule-wnnfns.c, nt.c, objects-msw.c, process-nt.c, realpath.c, redisplay-gtk.c, redisplay-output.c, redisplay-x.c, redisplay.c, search.c, select-msw.c, sysdep.c, syswindows.h, text.c, text.h, ui-byhand.c: Fix Raymond Toy's crash. Repeat to self: 2^21 - 1 is NOT the same as (2 << 21) - 1. Fix crashes due to excessive alloca(). replace alloca() with ALLOCA(), which calls the C alloca() [which uses xmalloc()] when the size is too big. Insert in various places calls to try to flush the C alloca() stored info if there is any. Add MALLOC_OR_ALLOCA(), for places that expect to be alloca()ing large blocks. This xmalloc()s when too large and records an unwind-protect to free -- relying on the caller to unbind_to() elsewhere in the function. Use it in concat(). Use MALLOC instead of ALLOCA in select-msw.c. xemacs.mak: Add alloca.o.
author ben
date Thu, 23 May 2002 11:46:46 +0000
parents 047d37eb70d7
children 2b6fa2618f76
comparison
equal deleted inserted replaced
850:f915ad7befaf 851:e7ee5f8bde58
572 /* If the file name has special constructs in it, 572 /* If the file name has special constructs in it,
573 call the corresponding file handler. */ 573 call the corresponding file handler. */
574 handler = Ffind_file_name_handler (directory, Qdirectory_file_name); 574 handler = Ffind_file_name_handler (directory, Qdirectory_file_name);
575 if (!NILP (handler)) 575 if (!NILP (handler))
576 return call2_check_string (handler, Qdirectory_file_name, directory); 576 return call2_check_string (handler, Qdirectory_file_name, directory);
577 buf = (Intbyte *) alloca (XSTRING_LENGTH (directory) + 20); 577 buf = (Intbyte *) ALLOCA (XSTRING_LENGTH (directory) + 20);
578 directory_file_name (XSTRING_DATA (directory), buf); 578 directory_file_name (XSTRING_DATA (directory), buf);
579 return build_intstring (buf); 579 return build_intstring (buf);
580 } 580 }
581 581
582 /* Fmake_temp_name used to be a simple wrapper around mktemp(), but it 582 /* Fmake_temp_name used to be a simple wrapper around mktemp(), but it
974 } 974 }
975 else /* ~user/filename */ 975 else /* ~user/filename */
976 { 976 {
977 for (p = nm; *p && (!IS_DIRECTORY_SEP (*p)); p++) 977 for (p = nm; *p && (!IS_DIRECTORY_SEP (*p)); p++)
978 DO_NOTHING; 978 DO_NOTHING;
979 o = (Intbyte *) alloca (p - nm + 1); 979 o = (Intbyte *) ALLOCA (p - nm + 1);
980 memcpy (o, nm, p - nm); 980 memcpy (o, nm, p - nm);
981 o [p - nm] = 0; 981 o [p - nm] = 0;
982 982
983 /* #### While NT is single-user (for the moment) you still 983 /* #### While NT is single-user (for the moment) you still
984 can have multiple user profiles users defined, each with 984 can have multiple user profiles users defined, each with
1044 } 1044 }
1045 #endif /* WIN32_NATIVE */ 1045 #endif /* WIN32_NATIVE */
1046 if (!newdir) 1046 if (!newdir)
1047 { 1047 {
1048 /* Either nm starts with /, or drive isn't mounted. */ 1048 /* Either nm starts with /, or drive isn't mounted. */
1049 newdir = (Intbyte *) alloca (4); 1049 newdir = (Intbyte *) ALLOCA (4);
1050 newdir[0] = DRIVE_LETTER (drive); 1050 newdir[0] = DRIVE_LETTER (drive);
1051 newdir[1] = ':'; 1051 newdir[1] = ':';
1052 newdir[2] = '/'; 1052 newdir[2] = '/';
1053 newdir[3] = 0; 1053 newdir[3] = 0;
1054 } 1054 }
1108 drive = newdir[0]; 1108 drive = newdir[0];
1109 newdir += 2; 1109 newdir += 2;
1110 } 1110 }
1111 if (!IS_DIRECTORY_SEP (nm[0])) 1111 if (!IS_DIRECTORY_SEP (nm[0]))
1112 { 1112 {
1113 Intbyte *tmp = (Intbyte *) alloca (qxestrlen (newdir) + 1113 Intbyte *tmp = (Intbyte *) ALLOCA (qxestrlen (newdir) +
1114 qxestrlen (nm) + 2); 1114 qxestrlen (nm) + 2);
1115 file_name_as_directory (tmp, newdir); 1115 file_name_as_directory (tmp, newdir);
1116 qxestrcat (tmp, nm); 1116 qxestrcat (tmp, nm);
1117 nm = tmp; 1117 nm = tmp;
1118 } 1118 }
1150 { 1150 {
1151 if (IS_DIRECTORY_SEP (newdir[0]) && IS_DIRECTORY_SEP (newdir[1])) 1151 if (IS_DIRECTORY_SEP (newdir[0]) && IS_DIRECTORY_SEP (newdir[1]))
1152 { 1152 {
1153 newdir = 1153 newdir =
1154 (Intbyte *) 1154 (Intbyte *)
1155 qxestrcpy ((Intbyte *) alloca (qxestrlen (newdir) + 1), 1155 qxestrcpy ((Intbyte *) ALLOCA (qxestrlen (newdir) + 1),
1156 newdir); 1156 newdir);
1157 p = newdir + 2; 1157 p = newdir + 2;
1158 while (*p && !IS_DIRECTORY_SEP (*p)) p++; 1158 while (*p && !IS_DIRECTORY_SEP (*p)) p++;
1159 p++; 1159 p++;
1160 while (*p && !IS_DIRECTORY_SEP (*p)) p++; 1160 while (*p && !IS_DIRECTORY_SEP (*p)) p++;
1175 #ifdef WIN32_FILENAMES 1175 #ifdef WIN32_FILENAMES
1176 && !(length == 2 && IS_DIRECTORY_SEP (newdir[0])) 1176 && !(length == 2 && IS_DIRECTORY_SEP (newdir[0]))
1177 #endif 1177 #endif
1178 ) 1178 )
1179 { 1179 {
1180 Intbyte *temp = (Intbyte *) alloca (length); 1180 Intbyte *temp = (Intbyte *) ALLOCA (length);
1181 memcpy (temp, newdir, length - 1); 1181 memcpy (temp, newdir, length - 1);
1182 temp[length - 1] = 0; 1182 temp[length - 1] = 0;
1183 newdir = temp; 1183 newdir = temp;
1184 } 1184 }
1185 tlen = length + 1; 1185 tlen = length + 1;
1191 tlen += qxestrlen (nm) + 1; 1191 tlen += qxestrlen (nm) + 1;
1192 #ifdef WIN32_FILENAMES 1192 #ifdef WIN32_FILENAMES
1193 /* Reserve space for drive specifier and escape prefix, since either 1193 /* Reserve space for drive specifier and escape prefix, since either
1194 or both may need to be inserted. (The Microsoft x86 compiler 1194 or both may need to be inserted. (The Microsoft x86 compiler
1195 produces incorrect code if the following two lines are combined.) */ 1195 produces incorrect code if the following two lines are combined.) */
1196 target = (Intbyte *) alloca (tlen + 4); 1196 target = (Intbyte *) ALLOCA (tlen + 4);
1197 target += 4; 1197 target += 4;
1198 #else /* not WIN32_FILENAMES */ 1198 #else /* not WIN32_FILENAMES */
1199 target = (Intbyte *) alloca (tlen); 1199 target = (Intbyte *) ALLOCA (tlen);
1200 #endif /* not WIN32_FILENAMES */ 1200 #endif /* not WIN32_FILENAMES */
1201 *target = 0; 1201 *target = 0;
1202 1202
1203 if (newdir) 1203 if (newdir)
1204 { 1204 {
1548 while (p != endp && (isalnum (*p) || *p == '_')) p++; 1548 while (p != endp && (isalnum (*p) || *p == '_')) p++;
1549 s = p; 1549 s = p;
1550 } 1550 }
1551 1551
1552 /* Copy out the variable name */ 1552 /* Copy out the variable name */
1553 target = (Intbyte *) alloca (s - o + 1); 1553 target = (Intbyte *) ALLOCA (s - o + 1);
1554 qxestrncpy (target, o, s - o); 1554 qxestrncpy (target, o, s - o);
1555 target[s - o] = 0; 1555 target[s - o] = 0;
1556 #ifdef WIN32_NATIVE 1556 #ifdef WIN32_NATIVE
1557 strupr (target); /* $home == $HOME etc. */ 1557 strupr (target); /* $home == $HOME etc. */
1558 #endif /* WIN32_NATIVE */ 1558 #endif /* WIN32_NATIVE */
1567 if (!substituted) 1567 if (!substituted)
1568 return filename; 1568 return filename;
1569 1569
1570 /* If substitution required, recopy the filename and do it */ 1570 /* If substitution required, recopy the filename and do it */
1571 /* Make space in stack frame for the new copy */ 1571 /* Make space in stack frame for the new copy */
1572 xnm = (Intbyte *) alloca (XSTRING_LENGTH (filename) + total + 1); 1572 xnm = (Intbyte *) ALLOCA (XSTRING_LENGTH (filename) + total + 1);
1573 x = xnm; 1573 x = xnm;
1574 1574
1575 /* Copy the rest of the name through, replacing $ constructs with values */ 1575 /* Copy the rest of the name through, replacing $ constructs with values */
1576 for (p = nm; *p;) 1576 for (p = nm; *p;)
1577 if (*p != '$') 1577 if (*p != '$')
1599 while (p != endp && (isalnum (*p) || *p == '_')) p++; 1599 while (p != endp && (isalnum (*p) || *p == '_')) p++;
1600 s = p; 1600 s = p;
1601 } 1601 }
1602 1602
1603 /* Copy out the variable name */ 1603 /* Copy out the variable name */
1604 target = (Intbyte *) alloca (s - o + 1); 1604 target = (Intbyte *) ALLOCA (s - o + 1);
1605 qxestrncpy (target, o, s - o); 1605 qxestrncpy (target, o, s - o);
1606 target[s - o] = 0; 1606 target[s - o] = 0;
1607 #ifdef WIN32_NATIVE 1607 #ifdef WIN32_NATIVE
1608 strupr (target); /* $home == $HOME etc. */ 1608 strupr (target); /* $home == $HOME etc. */
1609 #endif /* WIN32_NATIVE */ 1609 #endif /* WIN32_NATIVE */
3661 CHECK_STRING (string); 3661 CHECK_STRING (string);
3662 CHECK_STRING (key); 3662 CHECK_STRING (key);
3663 3663
3664 extra = XSTRING_LENGTH (string) % CRYPT_BLOCK_SIZE; 3664 extra = XSTRING_LENGTH (string) % CRYPT_BLOCK_SIZE;
3665 rounded_size = XSTRING_LENGTH (string) + extra; 3665 rounded_size = XSTRING_LENGTH (string) + extra;
3666 encrypted_string = alloca (rounded_size + 1); 3666 encrypted_string = ALLOCA (rounded_size + 1);
3667 memcpy (encrypted_string, XSTRING_DATA (string), XSTRING_LENGTH (string)); 3667 memcpy (encrypted_string, XSTRING_DATA (string), XSTRING_LENGTH (string));
3668 memset (encrypted_string + rounded_size - extra, 0, extra + 1); 3668 memset (encrypted_string + rounded_size - extra, 0, extra + 1);
3669 3669
3670 key_size = min (CRYPT_KEY_SIZE, XSTRING_LENGTH (key)) 3670 key_size = min (CRYPT_KEY_SIZE, XSTRING_LENGTH (key))
3671 3671
3672 raw_key = alloca (CRYPT_KEY_SIZE + 1); 3672 raw_key = ALLOCA (CRYPT_KEY_SIZE + 1);
3673 memcpy (raw_key, XSTRING_DATA (key), key_size); 3673 memcpy (raw_key, XSTRING_DATA (key), key_size);
3674 memset (raw_key + key_size, 0, (CRYPT_KEY_SIZE + 1) - key_size); 3674 memset (raw_key + key_size, 0, (CRYPT_KEY_SIZE + 1) - key_size);
3675 3675
3676 ecb_crypt (raw_key, encrypted_string, rounded_size, 3676 ecb_crypt (raw_key, encrypted_string, rounded_size,
3677 DES_ENCRYPT | DES_SW); 3677 DES_ENCRYPT | DES_SW);
3689 3689
3690 CHECK_STRING (string); 3690 CHECK_STRING (string);
3691 CHECK_STRING (key); 3691 CHECK_STRING (key);
3692 3692
3693 string_size = XSTRING_LENGTH (string) + 1; 3693 string_size = XSTRING_LENGTH (string) + 1;
3694 decrypted_string = alloca (string_size); 3694 decrypted_string = ALLOCA (string_size);
3695 memcpy (decrypted_string, XSTRING_DATA (string), string_size); 3695 memcpy (decrypted_string, XSTRING_DATA (string), string_size);
3696 decrypted_string[string_size - 1] = '\0'; 3696 decrypted_string[string_size - 1] = '\0';
3697 3697
3698 key_size = min (CRYPT_KEY_SIZE, XSTRING_LENGTH (key)) 3698 key_size = min (CRYPT_KEY_SIZE, XSTRING_LENGTH (key))
3699 3699
3700 raw_key = alloca (CRYPT_KEY_SIZE + 1); 3700 raw_key = ALLOCA (CRYPT_KEY_SIZE + 1);
3701 memcpy (raw_key, XSTRING_DATA (key), key_size); 3701 memcpy (raw_key, XSTRING_DATA (key), key_size);
3702 memset (raw_key + key_size, 0, (CRYPT_KEY_SIZE + 1) - key_size); 3702 memset (raw_key + key_size, 0, (CRYPT_KEY_SIZE + 1) - key_size);
3703 3703
3704 3704
3705 ecb_crypt (raw_key, decrypted_string, string_size, D | DES_SW); 3705 ecb_crypt (raw_key, decrypted_string, string_size, D | DES_SW);