Przeglądaj źródła

Fix to_8_3: stop at NUL terminator (extension-less filenames)

cat/run passed a fixed 64-char length, so the 8.3 mangler scanned past the
NUL into garbage and built a wrong name for names without a dot — 'cat test'
couldn't find the file that 'save test hello' had just written.
Johannes Zellner 1 miesiąc temu
rodzic
commit
89904ced0c
4 zmienionych plików z 8 dodań i 8 usunięć
  1. 2 2
      cat.c
  2. 2 2
      rm.c
  3. 2 2
      run.c
  4. 2 2
      save.c

+ 2 - 2
cat.c

@@ -12,7 +12,7 @@ static void to_8_3(const char *in, unsigned int in_len, char *out)
 	for (i = 0; i < in_len && in[i] == ' '; i++)
 		;
 	dot = i;
-	while (dot < in_len && in[dot] != '.' && in[dot] != ' ')
+	while (dot < in_len && in[dot] != '\0' && in[dot] != '.' && in[dot] != ' ')
 		dot++;
 	j = 0;
 	while (i < dot && j < 8) {
@@ -23,7 +23,7 @@ static void to_8_3(const char *in, unsigned int in_len, char *out)
 		out[j++] = ' ';
 	if (i < in_len && in[i] == '.')
 		i++;
-	while (i < in_len && in[i] != ' ' && j < 11) {
+	while (i < in_len && in[i] != '\0' && in[i] != ' ' && j < 11) {
 		out[j++] = (char)(in[i] >= 'a' && in[i] <= 'z' ? in[i] - 32 : in[i]);
 		i++;
 	}

+ 2 - 2
rm.c

@@ -11,7 +11,7 @@ static void to_8_3(const char *in, unsigned int in_len, char *out)
 	for (i = 0; i < in_len && in[i] == ' '; i++)
 		;
 	dot = i;
-	while (dot < in_len && in[dot] != '.' && in[dot] != ' ')
+	while (dot < in_len && in[dot] != '\0' && in[dot] != '.' && in[dot] != ' ')
 		dot++;
 	j = 0;
 	while (i < dot && j < 8) {
@@ -22,7 +22,7 @@ static void to_8_3(const char *in, unsigned int in_len, char *out)
 		out[j++] = ' ';
 	if (i < in_len && in[i] == '.')
 		i++;
-	while (i < in_len && in[i] != ' ' && j < 11) {
+	while (i < in_len && in[i] != '\0' && in[i] != ' ' && j < 11) {
 		out[j++] = (char)(in[i] >= 'a' && in[i] <= 'z' ? in[i] - 32 : in[i]);
 		i++;
 	}

+ 2 - 2
run.c

@@ -18,7 +18,7 @@ static void to_8_3(const char *in, unsigned int in_len, char *out)
 	for (i = 0; i < in_len && in[i] == ' '; i++)
 		;
 	dot = i;
-	while (dot < in_len && in[dot] != '.' && in[dot] != ' ')
+	while (dot < in_len && in[dot] != '\0' && in[dot] != '.' && in[dot] != ' ')
 		dot++;
 	j = 0;
 	while (i < dot && j < 8) {
@@ -29,7 +29,7 @@ static void to_8_3(const char *in, unsigned int in_len, char *out)
 		out[j++] = ' ';
 	if (i < in_len && in[i] == '.')
 		i++;
-	while (i < in_len && in[i] != ' ' && j < 11) {
+	while (i < in_len && in[i] != '\0' && in[i] != ' ' && j < 11) {
 		out[j++] = (char)(in[i] >= 'a' && in[i] <= 'z' ? in[i] - 32 : in[i]);
 		i++;
 	}

+ 2 - 2
save.c

@@ -12,7 +12,7 @@ static void to_8_3(const char *in, unsigned int in_len, char *out)
 	for (i = 0; i < in_len && in[i] == ' '; i++)
 		;
 	dot = i;
-	while (dot < in_len && in[dot] != '.' && in[dot] != ' ')
+	while (dot < in_len && in[dot] != '\0' && in[dot] != '.' && in[dot] != ' ')
 		dot++;
 	j = 0;
 	while (i < dot && j < 8) {
@@ -23,7 +23,7 @@ static void to_8_3(const char *in, unsigned int in_len, char *out)
 		out[j++] = ' ';
 	if (i < in_len && in[i] == '.')
 		i++;
-	while (i < in_len && in[i] != ' ' && j < 11) {
+	while (i < in_len && in[i] != '\0' && in[i] != ' ' && j < 11) {
 		out[j++] = (char)(in[i] >= 'a' && in[i] <= 'z' ? in[i] - 32 : in[i]);
 		i++;
 	}