OSDN Git Service

get_rnd_line()の対象になるファイルで, 先頭が数字で後に数字以外が続く行であっても
authornothere <nothere@0568b783-4c39-0410-ac80-bf13821ea2a2>
Fri, 9 May 2003 04:33:46 +0000 (04:33 +0000)
committernothere <nothere@0568b783-4c39-0410-ac80-bf13821ea2a2>
Fri, 9 May 2003 04:33:46 +0000 (04:33 +0000)
行数設定とみなされて, その結果行数が設定され直したり意図した行が出ない場合が
あったバグを修正.

src/files.c

index 6c9ea2e..1ad8392 100644 (file)
@@ -6842,7 +6842,7 @@ errr get_rnd_line(cptr file_name, int entry, char *output)
 {
        FILE    *fp;
        char    buf[1024];
-       int     line, counter, test, numentries;
+       int     line, counter, test, numentries = 0;
        int     line_num = 0;
 
 
@@ -6912,9 +6912,8 @@ errr get_rnd_line(cptr file_name, int entry, char *output)
                        my_fclose(fp);
                        return (-1);
                }
-
        }
-       
+
        /* Get the number of entries */
        while (TRUE)
        {
@@ -6927,9 +6926,24 @@ errr get_rnd_line(cptr file_name, int entry, char *output)
                        /* Look for the number of entries */
                        if (isdigit(buf[0]))
                        {
+                               int i;
+                               bool digit = TRUE;
+
+                               for (i = 1; buf[i] && (buf[i] != '\n') && (buf[i] != '\r'); i++)
+                               {
+                                       if (!isdigit(buf[i]))
+                                       {
+                                               digit = FALSE;
+                                               break;
+                                       }
+                               }
+
                                /* Get the number of entries */
-                               numentries = atoi(buf);
-                               break;
+                               if (digit)
+                               {
+                                       numentries = atoi(buf);
+                                       break;
+                               }
                        }
                }
                else