mercurial/cext/manifest.c
changeset 40646 9eeda7199181
parent 38803 5405cb1a7901
child 40647 f27f8e9ef1e7
equal deleted inserted replaced
40645:fa33196088c4 40646:9eeda7199181
    36 } lazymanifest;
    36 } lazymanifest;
    37 
    37 
    38 #define MANIFEST_OOM -1
    38 #define MANIFEST_OOM -1
    39 #define MANIFEST_NOT_SORTED -2
    39 #define MANIFEST_NOT_SORTED -2
    40 #define MANIFEST_MALFORMED -3
    40 #define MANIFEST_MALFORMED -3
       
    41 #define MANIFEST_BOGUS_FILENAME -4
    41 
    42 
    42 /* get the length of the path for a line */
    43 /* get the length of the path for a line */
    43 static size_t pathlen(line *l)
    44 static size_t pathlen(line *l)
    44 {
    45 {
    45 	const char *end = memchr(l->start, '\0', l->len);
    46 	const char *end = memchr(l->start, '\0', l->len);
   113 static int find_lines(lazymanifest *self, char *data, Py_ssize_t len)
   114 static int find_lines(lazymanifest *self, char *data, Py_ssize_t len)
   114 {
   115 {
   115 	char *prev = NULL;
   116 	char *prev = NULL;
   116 	while (len > 0) {
   117 	while (len > 0) {
   117 		line *l;
   118 		line *l;
   118 		char *next = memchr(data, '\n', len);
   119 		char *next;
       
   120 		if (*data == '\0') {
       
   121 			/* It's implausible there's no filename, don't
       
   122 			 * even bother looking for the newline. */
       
   123 			return MANIFEST_BOGUS_FILENAME;
       
   124 		}
       
   125 		next = memchr(data, '\n', len);
   119 		if (!next) {
   126 		if (!next) {
   120 			return MANIFEST_MALFORMED;
   127 			return MANIFEST_MALFORMED;
   121 		}
   128 		}
   122 		next++; /* advance past newline */
   129 		next++; /* advance past newline */
   123 		if (!realloc_if_full(self)) {
   130 		if (!realloc_if_full(self)) {
   187 			     "Manifest lines not in sorted order.");
   194 			     "Manifest lines not in sorted order.");
   188 		break;
   195 		break;
   189 	case MANIFEST_MALFORMED:
   196 	case MANIFEST_MALFORMED:
   190 		PyErr_Format(PyExc_ValueError,
   197 		PyErr_Format(PyExc_ValueError,
   191 			     "Manifest did not end in a newline.");
   198 			     "Manifest did not end in a newline.");
       
   199 		break;
       
   200 	case MANIFEST_BOGUS_FILENAME:
       
   201 		PyErr_Format(
       
   202 			PyExc_ValueError,
       
   203 			"Manifest had an entry with a zero-length filename.");
   192 		break;
   204 		break;
   193 	default:
   205 	default:
   194 		PyErr_Format(PyExc_ValueError,
   206 		PyErr_Format(PyExc_ValueError,
   195 			     "Unknown problem parsing manifest.");
   207 			     "Unknown problem parsing manifest.");
   196 	}
   208 	}