• R/O
  • HTTP
  • SSH
  • HTTPS

hengband: Commit

変愚蛮怒のメインリポジトリです


Commit MetaInfo

Revision940d8470dd8f62580e7f674ca4aab930dfee3d6a (tree)
Time2002-06-03 16:07:03
Authormogami <mogami@0568...>
Commitermogami

Log Message

大量の文字列をKで消したときに配列外に'\0'を書き込んでいたのを修正。
Y と H の動作をよりemacs likeに調整。

Change Summary

Incremental Difference

--- a/src/autopick.c
+++ b/src/autopick.c
@@ -2800,11 +2800,19 @@ void do_cmd_edit_autopick(void)
28002800 /* Paste killed text */
28012801 if (strlen(yank_buf))
28022802 {
2803- cx = 0;
28042803 for (j = 0; yank_buf[j]; j += strlen(yank_buf + j) + 1)
28052804 {
2806- insert_return_code(lines_list, 0, cy);
2807- lines_list[cy] = string_make(yank_buf + j);
2805+ /* Split current line */
2806+ insert_return_code(lines_list, cx, cy);
2807+
2808+ /* Paste yank buffer */
2809+ strcpy(buf, lines_list[cy]);
2810+ strncat(buf, yank_buf + j, 1024);
2811+ string_free(lines_list[cy]);
2812+ lines_list[cy] = string_make(buf);
2813+
2814+ /* Move to the beggining of next line */
2815+ cx = 0;
28082816 cy++;
28092817 }
28102818
@@ -2821,29 +2829,34 @@ void do_cmd_edit_autopick(void)
28212829
28222830 case KTRL('k'):
28232831 /* Kill rest of line */
2824- if (lines_list[cy][0] != '\0' && (unsigned int) cx < strlen(lines_list[cy]))
2832+ if (lines_list[cy][0] != '\0' && (uint)cx < strlen(lines_list[cy]))
28252833 {
2826- for (i = j = 0; lines_list[cy][i] && i < cx; i++)
2834+ /* Save preceding string */
2835+ for (i = 0; lines_list[cy][i] && i < cx; i++)
28272836 {
28282837 #ifdef JP
28292838 if (iskanji(lines_list[cy][i]))
2830- buf[j++] = lines_list[cy][i++];
2839+ {
2840+ buf[i] = lines_list[cy][i];
2841+ i++;
2842+ }
28312843 #endif
2832- buf[j++] = lines_list[cy][i];
2844+ buf[i] = lines_list[cy][i];
28332845 }
2834- buf[j] = '\0';
2846+ buf[i] = '\0';
28352847
28362848 j = 0;
28372849 if (old_key == KTRL('k'))
28382850 while (yank_buf[j])
28392851 j += strlen(yank_buf + j) + 1;
28402852
2841- if (j < MAX_YANK - 2)
2842- {
2843- strncpy(yank_buf + j, lines_list[cy] + i, MAX_YANK-j-2);
2844- yank_buf[MAX_YANK-2] = '\0';
2845- yank_buf[j + strlen(lines_list[cy] + i) + 1] = '\0';
2846- }
2853+ /* Copy following to yank buffer */
2854+ while (lines_list[cy][i] && j < MAX_YANK - 2)
2855+ yank_buf[j++] = lines_list[cy][i++];
2856+ yank_buf[j++] = '\0';
2857+ yank_buf[j] = '\0';
2858+
2859+ /* Replace current line with 'preceding string' */
28472860 string_free(lines_list[cy]);
28482861 lines_list[cy] = string_make(buf);
28492862
@@ -2859,6 +2872,11 @@ void do_cmd_edit_autopick(void)
28592872 if (iskanji(lines_list[cy][cx])) cx++;
28602873 #endif
28612874 cx++;
2875+
2876+ /* fall through */
2877+
2878+ case '\010':
2879+ /* BACK SPACE */
28622880 len = strlen(lines_list[cy]);
28632881 if (len < cx)
28642882 {
@@ -2874,10 +2892,6 @@ void do_cmd_edit_autopick(void)
28742892 }
28752893 }
28762894
2877- /* fall through */
2878-
2879- case '\010':
2880- /* BACK SPACE */
28812895 if (cx == 0)
28822896 {
28832897 /* delete a return code and union two lines */
Show on old repository browser