aboutsummaryrefslogtreecommitdiffstats
path: root/util.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2010-07-29 22:59:54 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2010-07-29 22:59:54 +0000
commit7ae7ac4abab04f4351ae84f63f81b61a41843aff (patch)
treede41136ca6ffb27f28729ecaf219e4fdea2bfbe6 /util.c
parentbc8e65073588035b6d6d272be8c697a8dc27ee81 (diff)
downloadruby-7ae7ac4abab04f4351ae84f63f81b61a41843aff.tar.gz
* util.c (ruby_add_suffix): fixed a bug returning uninitialized
value. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@28794 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'util.c')
-rw-r--r--util.c17
1 files changed, 11 insertions, 6 deletions
diff --git a/util.c b/util.c
index 48c212ec6a..a3fbd08c46 100644
--- a/util.c
+++ b/util.c
@@ -234,8 +234,9 @@ ruby_strtoul(const char *str, char **endptr, int base)
* suffix = ".bak" (style 1)
* foo.bar => foo.bak
* foo.bak => foo.$$$ (fallback)
- * foo.$$$ => foo.~~~ (fallback)
* makefile => makefile.bak
+ * suffix = ".$$$" (style 1)
+ * foo.$$$ => foo.~~~ (fallback)
*
* suffix = "~" (style 2)
* foo.c => foo.c~
@@ -291,7 +292,10 @@ ruby_add_suffix(VALUE str, const char *suffix)
if (*suffix == '.') { /* Style 1 */
if (ext) {
- if (strEQ(ext, suffix)) goto fallback;
+ if (strEQ(ext, suffix)) {
+ extlen = sizeof(suffix1) - 1; /* suffix2 must be same length */
+ suffix = strEQ(suffix, suffix1) ? suffix2 : suffix1;
+ }
slen = ext - name;
}
rb_str_resize(str, slen);
@@ -306,12 +310,13 @@ ruby_add_suffix(VALUE str, const char *suffix)
p += slen;
p[len] = '\0';
if (suffix[1] == '\0') { /* Style 2 */
+ q = (char *)ruby_find_basename(buf, &baselen, 0);
if (len <= 3) {
+ if (len == 0 && baselen >= 8 && p + 3 <= buf + sizeof(buf)) p[len++] = '.'; /* DOSISH */
p[len] = *suffix;
p[++len] = '\0';
}
- else if ((q = (char *)ruby_find_basename(buf, &baselen, 0)) &&
- baselen < 8) {
+ else if (q && baselen < 8) {
q += baselen;
*q++ = *suffix;
if (ext) {
@@ -332,9 +337,9 @@ ruby_add_suffix(VALUE str, const char *suffix)
fallback:
(void)memcpy(p, !ext || strEQ(ext, suffix1) ? suffix2 : suffix1, 5);
}
+ rb_str_resize(str, strlen(buf));
+ memcpy(RSTRING_PTR(str), buf, RSTRING_LEN(str));
}
- rb_str_resize(str, strlen(buf));
- memcpy(RSTRING_PTR(str), buf, RSTRING_LEN(str));
}
static int