git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH v2 2/3] offset_1st_component(), dos_drive_prefix() return size_t

From
tboegi@web.de <tboegi@web.de>
Date
Dec 7, 2018, 17:04 UTC
Message-ID
<20181207170458.9036-1-tboegi@web.de>
In-Reply-To
<5bf18396.1c69fb81.20780.2b1d@mx.google.com>
From: Torsten Bögershausen <tboegi@web.de>

Change the return value for offset_1st_component(), has_dos_drive_prefix() and skip_dos_drive_prefix from int into size_t, which is the natural type for length of data in memory.

While at it, remove possible "parameter not used" warnings in for the non-Windows builds in git-compat-util.h

Signed-off-by: Torsten Bögershausen <tboegi@web.de>
---
 abspath.c             | 2 +-
 compat/mingw-cygwin.c | 6 +++---
 compat/mingw-cygwin.h | 4 ++--
 git-compat-util.h     | 8 +++++---
 setup.c               | 4 ++--
 5 files changed, 13 insertions(+), 11 deletions(-)
diff --git a/abspath.c b/abspath.c
index 9857985329..12055a1d8f 100644
--- a/abspath.c
+++ b/abspath.c
@@ -51,7 +51,7 @@ static void get_next_component(struct strbuf *next, struct strbuf *remaining)
 /* copies root part from remaining to resolved, canonicalizing it on the way */
 static void get_root_part(struct strbuf *resolved, struct strbuf *remaining)
 {
-	int offset = offset_1st_component(remaining->buf);
+	size_t offset = offset_1st_component(remaining->buf);
 
 	strbuf_reset(resolved);
 	strbuf_add(resolved, remaining->buf, offset);
diff --git a/compat/mingw-cygwin.c b/compat/mingw-cygwin.c
index c63d7acb9c..5552c3ac20 100644
--- a/compat/mingw-cygwin.c
+++ b/compat/mingw-cygwin.c
@@ -1,13 +1,13 @@
 #include "../git-compat-util.h"
 
-int mingw_cygwin_skip_dos_drive_prefix(char **path)
+size_t mingw_cygwin_skip_dos_drive_prefix(char **path)
 {
-	int ret = has_dos_drive_prefix(*path);
+	size_t ret = has_dos_drive_prefix(*path);
 	*path += ret;
 	return ret;
 }
 
-int mingw_cygwin_offset_1st_component(const char *path)
+size_t mingw_cygwin_offset_1st_component(const char *path)
 {
 	char *pos = (char *)path;
 
diff --git a/compat/mingw-cygwin.h b/compat/mingw-cygwin.h
index 66ccc909ae..0e8a0c9074 100644
--- a/compat/mingw-cygwin.h
+++ b/compat/mingw-cygwin.h
@@ -1,6 +1,6 @@
 #define has_dos_drive_prefix(path) \
 	(isalpha(*(path)) && (path)[1] == ':' ? 2 : 0)
-int mingw_cygwin_skip_dos_drive_prefix(char **path);
+size_t mingw_cygwin_skip_dos_drive_prefix(char **path);
 #define skip_dos_drive_prefix mingw_cygwin_skip_dos_drive_prefix
 static inline int mingw_cygwin_is_dir_sep(int c)
 {
@@ -16,5 +16,5 @@ static inline char *mingw_cygwin_find_last_dir_sep(const char *path)
 	return ret;
 }
 #define find_last_dir_sep mingw_cygwin_find_last_dir_sep
-int mingw_cygwin_offset_1st_component(const char *path);
+size_t mingw_cygwin_offset_1st_component(const char *path);
 #define offset_1st_component mingw_cygwin_offset_1st_component
diff --git a/git-compat-util.h b/git-compat-util.h
index 7ece969b22..65eaaf0d50 100644
--- a/git-compat-util.h
+++ b/git-compat-util.h
@@ -355,16 +355,18 @@ static inline int noop_core_config(const char *var, const char *value, void *cb)
 #endif
 
 #ifndef has_dos_drive_prefix
-static inline int git_has_dos_drive_prefix(const char *path)
+static inline size_t git_has_dos_drive_prefix(const char *path)
 {
+	(void)path;
 	return 0;
 }
 #define has_dos_drive_prefix git_has_dos_drive_prefix
 #endif
 
 #ifndef skip_dos_drive_prefix
-static inline int git_skip_dos_drive_prefix(char **path)
+static inline size_t git_skip_dos_drive_prefix(char **path)
 {
+	(void)path;
 	return 0;
 }
 #define skip_dos_drive_prefix git_skip_dos_drive_prefix
@@ -379,7 +381,7 @@ static inline int git_is_dir_sep(int c)
 #endif
 
 #ifndef offset_1st_component
-static inline int git_offset_1st_component(const char *path)
+static inline size_t git_offset_1st_component(const char *path)
 {
 	return is_dir_sep(path[0]);
 }
diff --git a/setup.c b/setup.c
index 1be5037f12..538bc1ff99 100644
--- a/setup.c
+++ b/setup.c
@@ -29,7 +29,7 @@ static int abspath_part_inside_repo(char *path)
 	size_t len;
 	size_t wtlen;
 	char *path0;
-	int off;
+	size_t off;
 	const char *work_tree = get_git_work_tree();
 
 	if (!work_tree)
@@ -800,7 +800,7 @@ static const char *setup_bare_git_dir(struct strbuf *cwd, int offset,
 				      struct repository_format *repo_fmt,
 				      int *nongit_ok)
 {
-	int root_len;
+	size_t root_len;
 
 	if (check_repository_format_gently(".", repo_fmt, nongit_ok))
 		return NULL;
-- 
2.19.0.271.gfe8321ec05
Previous: Achim GratzNext: tboegi@web.de
Message 32 of 56 in “Cygwin Git with Windows paths”
  1. Steven PennyNov 18, 2018
  2. Torsten BögershausenNov 18, 2018
  3. Steven PennyNov 18, 2018
  4. Torsten BögershausenNov 18, 2018
  5. Steven PennyNov 18, 2018
  6. Torsten BögershausenNov 18, 2018
  7. Steven PennyNov 18, 2018
  8. Junio C HamanoNov 19, 2018
  9. Randall S. BeckerNov 19, 2018
  10. Junio C HamanoNov 19, 2018
  11. Torsten BögershausenNov 19, 2018
  12. Steven PennyNov 20, 2018
  13. Torsten BögershausenNov 20, 2018
  14. Steven PennyNov 20, 2018
  15. Randall S. BeckerNov 19, 2018
  16. 1/1 'git clone <url> C:\cygwin\home\USER\repo' is working (again)tboegi@web.de, Nov 26, 2018
  17. Steven PennyNov 27, 2018
  18. Junio C HamanoNov 27, 2018
  19. Steven PennyNov 27, 2018
  20. Junio C HamanoNov 27, 2018
  21. Steven PennyNov 27, 2018
  22. Johannes SchindelinNov 27, 2018
  23. Junio C HamanoNov 28, 2018
  24. J.H. van de WaterNov 28, 2018
  25. Johannes SchindelinNov 28, 2018
  26. HouderNov 28, 2018
  27. Johannes SchindelinNov 28, 2018
  28. Achim GratzNov 27, 2018
  29. Johannes SchindelinNov 27, 2018
  30. Junio C HamanoNov 28, 2018
  31. Achim GratzNov 27, 2018
  32. 2/3 offset_1st_component(), dos_drive_prefix() return size_ttboegi@web.de, Dec 7, 2018
  33. 1/3 git clone <url> C:\cygwin\home\USER\repo' is working (again)tboegi@web.de, Dec 7, 2018
  34. Johannes SchindelinDec 7, 2018
  35. Steven PennyDec 8, 2018
  36. Johannes SchindelinDec 10, 2018
  37. Steven PennyDec 10, 2018
  38. Johannes SchindelinDec 11, 2018
  39. Steven PennyDec 12, 2018
  40. Johannes SixtDec 12, 2018
  41. Steven PennyDec 12, 2018
  42. Junio C HamanoDec 13, 2018
  43. Johannes SchindelinDec 12, 2018
  44. Elijah NewrenDec 12, 2018
  45. Johannes SchindelinDec 12, 2018
  46. 3/3 Refactor mingw_cygwin_offset_1st_component()tboegi@web.de, Dec 7, 2018
  47. Johannes SchindelinDec 7, 2018
  48. 1/1 git clone <url> C:\cygwin\home\USER\repo' is working (again)tboegi@web.de, Dec 8, 2018
  49. Steven PennyDec 8, 2018
  50. Junio C HamanoDec 9, 2018
  51. Johannes SchindelinDec 10, 2018
  52. Torsten BögershausenDec 11, 2018
  53. Johannes SchindelinDec 11, 2018
  54. Torsten BögershausenDec 11, 2018
  55. 1/1 git clone <url> C:\cygwin\home\USER\repo' is working (again)tboegi@web.de, Dec 15, 2018
  56. Achim GratzMay 2, 2019

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.