convert trivial sprintf / strcpy calls to xsnprintf
[gitweb.git] / builtin / init-db.c
index 4335738135df32aeea3712cbdae88bd862015969..e7d0e31f46e9890a267fa508fa43d184d563afed 100644 (file)
@@ -4,6 +4,7 @@
  * Copyright (C) Linus Torvalds, 2005
  */
 #include "cache.h"
+#include "refs.h"
 #include "builtin.h"
 #include "exec_cmd.h"
 #include "parse-options.h"
@@ -261,7 +262,8 @@ static int create_default_files(const char *template_path)
        }
 
        /* This forces creation of new config file */
-       sprintf(repo_version_string, "%d", GIT_REPO_VERSION);
+       xsnprintf(repo_version_string, sizeof(repo_version_string),
+                 "%d", GIT_REPO_VERSION);
        git_config_set("core.repositoryformatversion", repo_version_string);
 
        path[len] = 0;
@@ -377,7 +379,7 @@ static void separate_git_dir(const char *git_dir)
                        die_errno(_("unable to move %s to %s"), src, git_dir);
        }
 
-       write_file(git_link, 1, "gitdir: %s\n", git_dir);
+       write_file(git_link, "gitdir: %s", git_dir);
 }
 
 int init_db(const char *template_dir, unsigned int flags)
@@ -413,13 +415,13 @@ int init_db(const char *template_dir, unsigned int flags)
                 */
                if (shared_repository < 0)
                        /* force to the mode value */
-                       sprintf(buf, "0%o", -shared_repository);
+                       xsnprintf(buf, sizeof(buf), "0%o", -shared_repository);
                else if (shared_repository == PERM_GROUP)
-                       sprintf(buf, "%d", OLD_PERM_GROUP);
+                       xsnprintf(buf, sizeof(buf), "%d", OLD_PERM_GROUP);
                else if (shared_repository == PERM_EVERYBODY)
-                       sprintf(buf, "%d", OLD_PERM_EVERYBODY);
+                       xsnprintf(buf, sizeof(buf), "%d", OLD_PERM_EVERYBODY);
                else
-                       die("oops");
+                       die("BUG: invalid value for shared_repository");
                git_config_set("core.sharedrepository", buf);
                git_config_set("receive.denyNonFastforwards", "true");
        }