summaryrefslogtreecommitdiff
path: root/ruby.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-08-29 05:59:05 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-08-29 05:59:05 +0000
commit58d0277775487f835b6345c0c32c459163fd1f13 (patch)
treeeaacb6b9c9060c313b7767359fce2fbd4676637f /ruby.c
parentcc4c0ab8621a456cc070df9da74e58c4663b42d3 (diff)
ruby.c: magic numbers
* ruby.c (ruby_init_loadpath_safe): remove magic numbers. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@36845 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ruby.c')
-rw-r--r--ruby.c12
1 files changed, 10 insertions, 2 deletions
diff --git a/ruby.c b/ruby.c
index e6e4343..0fc5247 100644
--- a/ruby.c
+++ b/ruby.c
@@ -411,9 +411,17 @@ ruby_init_loadpath_safe(int safe_level)
#endif
p = strrchr(libpath, '/');
if (p) {
+ static const char bindir[] = "/bin";
+ static const char libdir[] = "/lib";
+ const ptrdiff_t bindir_len = (ptrdiff_t)sizeof(bindir) - 1;
+ const ptrdiff_t libdir_len = (ptrdiff_t)sizeof(libdir) - 1;
*p = 0;
- if (p - libpath > 3 && !(STRCASECMP(p - 4, "/bin") && strcmp(p - 4, "/lib"))) {
- p -= 4;
+ if (p - libpath >= bindir_len && !STRCASECMP(p - bindir_len, bindir)) {
+ p -= bindir_len;
+ *p = 0;
+ }
+ else if (p - libpath >= libdir_len && !strcmp(p - libdir_len, libdir)) {
+ p -= libdir_len;
*p = 0;
}
}