if (!strcmp(params->cur_key, "name")) {
const char *ws_name = (const char *)val;
- params->workspaces_walk->canonical_name = strndup(ws_name, len);
+ params->workspaces_walk->canonical_name = sstrndup(ws_name, len);
if (config.strip_ws_numbers && params->workspaces_walk->num >= 0) {
/* Special case: strip off the workspace number */
*/
char *sstrdup(const char *str);
+/**
+ * Safe-wrapper around strndup which exits if strndup returns NULL (meaning that
+ * there is no more memory available)
+ *
+ */
+char *sstrndup(const char *str, size_t size);
+
/**
* Safe-wrapper around asprintf which exits if it returns -1 (meaning that
* there is no more memory available)
char *head, *tail, *result;
tail = strchr(path, '/');
- head = strndup(path, tail ? (size_t)(tail - path) : strlen(path));
+ head = sstrndup(path, tail ? (size_t)(tail - path) : strlen(path));
int res = glob(head, GLOB_TILDE, NULL, &globbuf);
free(head);
return result;
}
+char *sstrndup(const char *str, size_t size) {
+ char *result = strndup(str, size);
+ if (result == NULL)
+ err(EXIT_FAILURE, "strndup()");
+ return result;
+}
+
int sasprintf(char **strp, const char *fmt, ...) {
va_list args;
int result;