]> git.ipfire.org Git - thirdparty/ccache.git/commitdiff
Remove usage of x_strdup
authorJoel Rosdahl <joel@rosdahl.net>
Fri, 17 Jul 2020 11:33:08 +0000 (13:33 +0200)
committerJoel Rosdahl <joel@rosdahl.net>
Fri, 17 Jul 2020 17:42:18 +0000 (19:42 +0200)
src/ccache.cpp
unittest/test_argprocessing.cpp

index b990d488970486bb5be982155e0362433a8de2a9..e2a457af7cd9efaec3d3c7e8f5706e2c36d44e19 100644 (file)
@@ -503,18 +503,16 @@ process_preprocessed_file(Context& ctx, Hash& hash, const char* path, bool pump)
         r++;
       }
       // p and q span the include file path.
-      char* inc_path = x_strndup(p, q - p);
+      std::string inc_path(p, q - p);
       if (!ctx.has_absolute_include_headers) {
         ctx.has_absolute_include_headers = Util::is_absolute_path(inc_path);
       }
-      char* saved_inc_path = inc_path;
-      inc_path = x_strdup(Util::make_relative_path(ctx, inc_path).c_str());
-      free(saved_inc_path);
+      inc_path = Util::make_relative_path(ctx, inc_path);
 
       bool should_hash_inc_path = true;
       if (!ctx.config.hash_dir()) {
         if (Util::starts_with(inc_path, ctx.apparent_cwd)
-            && str_endswith(inc_path, "//")) {
+            && Util::ends_with(inc_path, "//")) {
           // When compiling with -g or similar, GCC adds the absolute path to
           // CWD like this:
           //
@@ -530,7 +528,6 @@ process_preprocessed_file(Context& ctx, Hash& hash, const char* path, bool pump)
       }
 
       remember_include_file(ctx, inc_path, hash, system, nullptr);
-      free(inc_path);
       p = q; // Everything of interest between p and q has been hashed now.
     } else if (q[0] == '.' && q[1] == 'i' && q[2] == 'n' && q[3] == 'c'
                && q[4] == 'b' && q[5] == 'i' && q[6] == 'n') {
index 162b0f8c3ac81c88b919a3d406bb44fd8cec1f73..a3bb0b779181bdaaa490474e9a19404a62bb6492 100644 (file)
@@ -603,7 +603,7 @@ TEST_CASE("I_flag_with_concat_arg_should_be_rewritten_if_basedir_is_used")
   Args act_cc;
 
   Util::write_file("foo.c", "");
-  ctx.config.set_base_dir(x_strdup("/")); // posix
+  ctx.config.set_base_dir("/"); // posix
   // Windows path doesn't work concatenated.
   std::string cwd = get_posix_path(ctx.actual_cwd);
   std::string arg_string = fmt::format("cc -I{}/foo -c foo.c", cwd);