summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: ff1f994)
raw | patch | inline | side by side (parent: ff1f994)
author | Shawn O. Pearce <spearce@spearce.org> | |
Wed, 7 Mar 2007 01:44:17 +0000 (20:44 -0500) | ||
committer | Junio C Hamano <junkio@cox.net> | |
Wed, 7 Mar 2007 18:47:10 +0000 (10:47 -0800) |
We shouldn't attempt to assign constant strings into char*, as the
string is not writable at runtime. Likewise we should always be
treating unsigned values as unsigned values, not as signed values.
Most of these are very straightforward. The only exception is the
(unnecessary) xstrdup/free in builtin-branch.c for the detached
head case. Since this is a user-level interactive type program
and that particular code path is executed no more than once, I feel
that the extra xstrdup call is well worth the easy elimination of
this warning.
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
Signed-off-by: Junio C Hamano <junkio@cox.net>
string is not writable at runtime. Likewise we should always be
treating unsigned values as unsigned values, not as signed values.
Most of these are very straightforward. The only exception is the
(unnecessary) xstrdup/free in builtin-branch.c for the detached
head case. Since this is a user-level interactive type program
and that particular code path is executed no more than once, I feel
that the extra xstrdup call is well worth the easy elimination of
this warning.
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
Signed-off-by: Junio C Hamano <junkio@cox.net>
16 files changed:
builtin-blame.c | patch | blob | history | |
builtin-branch.c | patch | blob | history | |
builtin-for-each-ref.c | patch | blob | history | |
builtin-mailinfo.c | patch | blob | history | |
builtin-shortlog.c | patch | blob | history | |
builtin-show-branch.c | patch | blob | history | |
cache.h | patch | blob | history | |
commit.c | patch | blob | history | |
convert-objects.c | patch | blob | history | |
environment.c | patch | blob | history | |
fast-import.c | patch | blob | history | |
index-pack.c | patch | blob | history | |
interpolate.c | patch | blob | history | |
interpolate.h | patch | blob | history | |
path.c | patch | blob | history | |
sha1_file.c | patch | blob | history |
diff --git a/builtin-blame.c b/builtin-blame.c
index 9f7dd4e19f042ce91c4c21fb73e8e3f69ca78a76..20966b9e02449617d4fc9a91bbd616ce37ae547a 100644 (file)
--- a/builtin-blame.c
+++ b/builtin-blame.c
@@ -1244,26 +1244,26 @@ static void pass_blame(struct scoreboard *sb, struct origin *origin, int opt)
*/
struct commit_info
{
- char *author;
- char *author_mail;
+ const char *author;
+ const char *author_mail;
unsigned long author_time;
- char *author_tz;
+ const char *author_tz;
/* filled only when asked for details */
- char *committer;
- char *committer_mail;
+ const char *committer;
+ const char *committer_mail;
unsigned long committer_time;
- char *committer_tz;
+ const char *committer_tz;
- char *summary;
+ const char *summary;
};
/*
* Parse author/committer line in the commit object buffer
*/
static void get_ac_line(const char *inbuf, const char *what,
- int bufsz, char *person, char **mail,
- unsigned long *time, char **tz)
+ int bufsz, char *person, const char **mail,
+ unsigned long *time, const char **tz)
{
int len;
char *tmp, *endp;
if (bufsz <= len) {
error_out:
/* Ugh */
- person = *mail = *tz = "(unknown)";
+ *mail = *tz = "(unknown)";
*time = 0;
return;
}
diff --git a/builtin-branch.c b/builtin-branch.c
index d3718496553078dfb4ceac2413c758457e102592..06d8a8ce0432134f994aa30ac4133baf4ba7fef5 100644 (file)
--- a/builtin-branch.c
+++ b/builtin-branch.c
detached = (detached && (kinds & REF_LOCAL_BRANCH));
if (detached) {
struct ref_item item;
- item.name = "(no branch)";
+ item.name = xstrdup("(no branch)");
item.kind = REF_LOCAL_BRANCH;
hashcpy(item.sha1, head_sha1);
if (strlen(item.name) > ref_list.maxwidth)
ref_list.maxwidth = strlen(item.name);
print_ref_item(&item, ref_list.maxwidth, verbose, abbrev, 1);
+ free(item.name);
}
for (i = 0; i < ref_list.index; i++) {
diff --git a/builtin-for-each-ref.c b/builtin-for-each-ref.c
index b11ca928d6ac353de888f0e80d24578c5803d769..2b218425aab2c37a826bfbe22535f2e5b7002a26 100644 (file)
--- a/builtin-for-each-ref.c
+++ b/builtin-for-each-ref.c
@@ -301,7 +301,7 @@ static const char *find_wholine(const char *who, int wholen, const char *buf, un
return "";
}
-static char *copy_line(const char *buf)
+static const char *copy_line(const char *buf)
{
const char *eol = strchr(buf, '\n');
char *line;
return line;
}
-static char *copy_name(const char *buf)
+static const char *copy_name(const char *buf)
{
const char *eol = strchr(buf, '\n');
const char *eoname = strstr(buf, " <");
return line;
}
-static char *copy_email(const char *buf)
+static const char *copy_email(const char *buf)
{
const char *email = strchr(buf, '<');
const char *eoemail = strchr(email, '>');
diff --git a/builtin-mailinfo.c b/builtin-mailinfo.c
index 766a37ebe2da56f92be3927d6ddfe46dba9386df..f54e8752fb6dd0f7f251fe6bfe7bf3b2f8cd91f3 100644 (file)
--- a/builtin-mailinfo.c
+++ b/builtin-mailinfo.c
return 0;
}
-static void convert_to_utf8(char *line, char *charset)
+static void convert_to_utf8(char *line, const char *charset)
{
- static char latin_one[] = "latin1";
- char *input_charset = *charset ? charset : latin_one;
+ static const char latin_one[] = "latin1";
+ const char *input_charset = *charset ? charset : latin_one;
char *out = reencode_string(line, metainfo_charset, input_charset);
if (!out)
diff --git a/builtin-shortlog.c b/builtin-shortlog.c
index 2f71a2a6e2ecf556956a0271d8af9ad852d5a93c..2d7726e8b975d9977e14638cc127ed0b30d3058b 100644 (file)
--- a/builtin-shortlog.c
+++ b/builtin-shortlog.c
prepare_revision_walk(rev);
while ((commit = get_revision(rev)) != NULL) {
- char *author = NULL, *oneline, *buffer;
+ const char *author = NULL, *oneline, *buffer;
int authorlen = authorlen, onelinelen;
/* get author and oneline */
for (buffer = commit->buffer; buffer && *buffer != '\0' &&
*buffer != '\n'; ) {
- char *eol = strchr(buffer, '\n');
+ const char *eol = strchr(buffer, '\n');
if (eol == NULL)
eol = buffer + strlen(buffer);
diff --git a/builtin-show-branch.c b/builtin-show-branch.c
index 67ae6bacda6edda2e36b974c0d36b4611ef1a9a6..c892f1f7a643b3d7e5c298837424a72cbc2c4f78 100644 (file)
--- a/builtin-show-branch.c
+++ b/builtin-show-branch.c
}
for (i = 0; i < reflog; i++) {
- char *logmsg, *msg, *m;
+ char *logmsg, *m;
+ const char *msg;
unsigned long timestamp;
int tz;
index c291163e6d2096181ddf89954d2d65953d1ba687..f3d7538aab0359f423999d050f764a44cf99eb15 100644 (file)
--- a/cache.h
+++ b/cache.h
extern char git_default_name[MAX_GITNAME];
extern char *git_commit_encoding;
-extern char *git_log_output_encoding;
+extern const char *git_log_output_encoding;
extern int copy_fd(int ifd, int ofd);
extern int read_in_full(int fd, void *buf, size_t count);
diff --git a/commit.c b/commit.c
index 555252734298540ffc5678ac5d80888fd23dd4e5..5b9234e12e8d1ef46d0d53b15cea850dfbde14c2 100644 (file)
--- a/commit.c
+++ b/commit.c
}
}
-static char *replace_encoding_header(char *buf, char *encoding)
+static char *replace_encoding_header(char *buf, const char *encoding)
{
char *encoding_header = strstr(buf, "\nencoding ");
char *end_of_encoding_header;
}
static char *logmsg_reencode(const struct commit *commit,
- char *output_encoding)
+ const char *output_encoding)
{
+ static const char *utf8 = "utf-8";
+ const char *use_encoding;
char *encoding;
char *out;
- char *utf8 = "utf-8";
if (!*output_encoding)
return NULL;
encoding = get_header(commit, "encoding");
- if (!encoding)
- encoding = utf8;
- if (!strcmp(encoding, output_encoding))
+ use_encoding = encoding ? encoding : utf8;
+ if (!strcmp(use_encoding, output_encoding))
out = strdup(commit->buffer);
else
out = reencode_string(commit->buffer,
- output_encoding, encoding);
+ output_encoding, use_encoding);
if (out)
out = replace_encoding_header(out, output_encoding);
- if (encoding != utf8)
- free(encoding);
- if (!out)
- return NULL;
+ free(encoding);
return out;
}
const char *msg = commit->buffer;
int plain_non_ascii = 0;
char *reencoded;
- char *encoding;
+ const char *encoding;
if (fmt == CMIT_FMT_USERFORMAT)
return format_commit_message(commit, msg, buf, space);
diff --git a/convert-objects.c b/convert-objects.c
index b5f41ae2e38c1f7856d7f060955eed5da0aea036..4809f9199fa21dcd95ab508e26196080d49e8e88 100644 (file)
--- a/convert-objects.c
+++ b/convert-objects.c
@@ -132,7 +132,7 @@ static void convert_tree(void *buffer, unsigned long size, unsigned char *result
unsigned long orig_size = size;
while (size) {
- int len = 1+strlen(buffer);
+ size_t len = 1+strlen(buffer);
convert_binary_sha1((char *) buffer + len);
diff --git a/environment.c b/environment.c
index 49486dd9f161bd8e140c5a1b3346180ded51c069..0151ad07227d20a7f8d4a5c390d77b2aa85ef739 100644 (file)
--- a/environment.c
+++ b/environment.c
int warn_ambiguous_refs = 1;
int repository_format_version;
char *git_commit_encoding;
-char *git_log_output_encoding;
+const char *git_log_output_encoding;
int shared_repository = PERM_UMASK;
const char *apply_default_whitespace;
int zlib_compression_level = Z_DEFAULT_COMPRESSION;
diff --git a/fast-import.c b/fast-import.c
index cc3347b23d0c7dba1bc05c65cb58215c92bb8547..132dd9c938fc811b14bd141266afe3cd7c7f4302 100644 (file)
--- a/fast-import.c
+++ b/fast-import.c
static char *keep_pack(char *curr_index_name)
{
static char name[PATH_MAX];
- static char *keep_msg = "fast-import";
+ static const char *keep_msg = "fast-import";
int keep_fd;
chmod(pack_data->pack_name, 0444);
diff --git a/index-pack.c b/index-pack.c
index cf81a99500e9bf5fc0c0812a2172c5561dc65b68..b405864be954941dedc4b0cc0c7f7aefcf65dd2d 100644 (file)
--- a/index-pack.c
+++ b/index-pack.c
const char *keep_name, const char *keep_msg,
unsigned char *sha1)
{
- char *report = "pack";
+ const char *report = "pack";
char name[PATH_MAX];
int err;
diff --git a/interpolate.c b/interpolate.c
index f992ef77533737fe2ec52dc3b662cb6cacca0ea2..fb30694f4741147bba62350f704111d3afbf8133 100644 (file)
--- a/interpolate.c
+++ b/interpolate.c
const char *src = orig;
char *dest = result;
int newlen = 0;
- char *name, *value;
+ const char *name, *value;
int namelen, valuelen;
int i;
char c;
diff --git a/interpolate.h b/interpolate.h
index 190a180b587aa565ae2ae71f9eb068ad75db168f..16a26b998699a8a5a5b3472f4b57a574a292beef 100644 (file)
--- a/interpolate.h
+++ b/interpolate.h
*/
struct interp {
- char *name;
+ const char *name;
char *value;
};
index c5d25a4b903bd92930df4004d30d4dffa6054456..6395cf23098841c16d993ae7e86b2d8dcff01cd7 100644 (file)
--- a/path.c
+++ b/path.c
if (access("objects", X_OK) == 0 && access("refs", X_OK) == 0 &&
validate_headref("HEAD") == 0) {
- putenv("GIT_DIR=.");
+ setenv("GIT_DIR", ".", 1);
check_repository_format();
return path;
}
diff --git a/sha1_file.c b/sha1_file.c
index cfce7acdbd8b18416e707b694acc7c9496df16ed..b17a8287958a5af4e197ed6114eee255d1bc1b79 100644 (file)
--- a/sha1_file.c
+++ b/sha1_file.c
enum object_type type, const char *path)
{
unsigned long size = st->st_size;
- void *buf;
+ void *buf = NULL;
int ret, re_allocated = 0;
- buf = "";
if (size)
buf = xmmap(NULL, size, PROT_READ, MAP_PRIVATE, fd, 0);
close(fd);