##// END OF EJS Templates
pathencode: don't use alloca() for safety/portability
Matt Mackall -
r18452:8bd338c7 default
parent child Browse files
Show More
@@ -696,22 +696,22 b' static int sha1hash(char hash[20], const'
696 return 0;
696 return 0;
697 }
697 }
698
698
699 #define MAXENCODE 4096 * 3
700
699 static PyObject *hashencode(const char *src, Py_ssize_t len)
701 static PyObject *hashencode(const char *src, Py_ssize_t len)
700 {
702 {
701 const Py_ssize_t baselen = (len - 5) * 3;
703 char dired[MAXENCODE];
702 #ifndef _MSC_VER
704 char lowered[MAXENCODE];
703 /* alloca is surprisingly slow, so avoid when possible */
705 char auxed[MAXENCODE];
704 char dired[baselen];
706 Py_ssize_t dirlen, lowerlen, auxlen, baselen;
705 char lowered[baselen];
706 char auxed[baselen];
707 #else
708 char *dired = alloca(baselen);
709 char *lowered = alloca(baselen);
710 char *auxed = alloca(baselen);
711 #endif
712 Py_ssize_t dirlen, lowerlen, auxlen;
713 char sha[20];
707 char sha[20];
714
708
709 baselen = (len - 5) * 3;
710 if (baselen >= MAXENCODE) {
711 PyErr_SetString(PyExc_ValueError, "string too long");
712 return NULL;
713 }
714
715 dirlen = _encodedir(dired, baselen, src, len);
715 dirlen = _encodedir(dired, baselen, src, len);
716 if (sha1hash(sha, dired, dirlen - 1) == -1)
716 if (sha1hash(sha, dired, dirlen - 1) == -1)
717 return NULL;
717 return NULL;
General Comments 0
You need to be logged in to leave comments. Login now