Handle CRLF when reading XML on Windows
authorTom Tromey <tromey@adacore.com>
Tue, 10 Dec 2019 18:44:36 +0000 (11:44 -0700)
committerTom Tromey <tromey@adacore.com>
Thu, 19 Dec 2019 17:00:05 +0000 (10:00 -0700)
xml-support.c uses FOPEN_RT, but then reads the entire contents of the
file and verifies that the number of bytes read matches the length.
This can fail on Windows, where the read will translate line
terminators.

This patch fixes the bug by changing xml-support.c to use FOPEN_RB.
This works because expat correctly handles \r\n line terminators.

gdb/ChangeLog
2019-12-11  Tom Tromey  <tromey@adacore.com>

* xml-support.c (xml_fetch_content_from_file): Use FOPEN_RB.

gdb/testsuite/ChangeLog
2019-12-11  Tom Tromey  <tromey@adacore.com>

* gdb.xml/tdesc-arch.exp (set_arch): Add "trans_mode" parameter.
Add crlf test.

Change-Id: I548438f33eed284dde1de8babf755eaa1a40319d

gdb/ChangeLog
gdb/testsuite/ChangeLog
gdb/testsuite/gdb.xml/tdesc-arch.exp
gdb/xml-support.c

index 8e38ada5ea06a93bb736362106b219bfefc1bb3a..532dc6373af9fd0ad00276e93c3a31d1385b0555 100644 (file)
@@ -1,3 +1,7 @@
+2019-12-11  Tom Tromey  <tromey@adacore.com>
+
+       * xml-support.c (xml_fetch_content_from_file): Use FOPEN_RB.
+
 2019-12-18  Tom Tromey  <tromey@adacore.com>
 
        PR build/25268:
index 1079e71c84c0af4fa8db86e3a380670717f5b837..4f8d8517e3c0b1bc59bbfc1192f94ef2ce32667c 100644 (file)
@@ -1,3 +1,8 @@
+2019-12-11  Tom Tromey  <tromey@adacore.com>
+
+       * gdb.xml/tdesc-arch.exp (set_arch): Add "trans_mode" parameter.
+       Add crlf test.
+
 2019-12-18  Simon Marchi  <simon.marchi@efficios.com>
 
        * gdb.base/default.exp: Update value of $_gdb_major.
index 617ab0616b2157ca3ecdc9e3a2835d336db9e57a..d98e50e5624fb2fb505031c5315d8f40cf082efa 100644 (file)
@@ -55,13 +55,16 @@ if { "$arch1" == "" || "$arch2" == "" || "$default_arch" == "" } {
 
 # Run these tests twice, once for $arch1 and once for $arch2, to
 # make sure that the tdesc file overrides the global default.
+# TRANS_MODE indicates how newlines should be represented; it should
+# be one of the values supported by "fconfigure -translation".
 
-proc set_arch { arch which } {
+proc set_arch { arch which trans_mode } {
     global gdb_prompt
     global subdir
 
     set filename [standard_output_file tdesc-arch.xml]
     set fd [open $filename w]
+    fconfigure $fd -translation $trans_mode
     puts $fd \
        "<target>
            <architecture>$arch</architecture>
@@ -92,8 +95,13 @@ proc set_arch { arch which } {
     remote_file host delete $filename
 }
 
-set_arch $arch1 first
-set_arch $arch2 second
+set_arch $arch1 first lf
+set_arch $arch2 second lf
+
+with_test_prefix crlf {
+    set_arch $arch1 first crlf
+    set_arch $arch2 second crlf
+}
 
 # Check an invalid architecture setting.
 set filename [standard_output_file tdesc-arch.xml]
index f5a142754578e18572874406258cb2e2c0d0fcc0..0f0806f8ee047b19ce9999b2095ff3bc87389ea1 100644 (file)
@@ -977,11 +977,11 @@ xml_fetch_content_from_file (const char *filename, void *baton)
     {
       char *fullname = concat (dirname, "/", filename, (char *) NULL);
 
-      file = gdb_fopen_cloexec (fullname, FOPEN_RT);
+      file = gdb_fopen_cloexec (fullname, FOPEN_RB);
       xfree (fullname);
     }
   else
-    file = gdb_fopen_cloexec (filename, FOPEN_RT);
+    file = gdb_fopen_cloexec (filename, FOPEN_RB);
 
   if (file == NULL)
     return {};
This page took 0.036317 seconds and 4 git commands to generate.