summaryrefslogtreecommitdiffstats
path: root/libversion/gitversion.cpp.in
diff options
context:
space:
mode:
Diffstat (limited to 'libversion/gitversion.cpp.in')
-rw-r--r--libversion/gitversion.cpp.in17
1 files changed, 12 insertions, 5 deletions
diff --git a/libversion/gitversion.cpp.in b/libversion/gitversion.cpp.in
index 164b50b..50ce1d2 100644
--- a/libversion/gitversion.cpp.in
+++ b/libversion/gitversion.cpp.in
@@ -6,11 +6,18 @@
* - No git information is present (no .git directory)
* in those cases clear the gitVersionString (would have string GIT-NOTFOUND).
*/
-char *getGitVersion(void)
+const char *getGitVersion(void)
{
- static char gitVersionString[100];
- strcpy(gitVersionString,"@GIT_HEAD_SHA1@");
- strcat(gitVersionString,!strcmp("@GIT_IS_DIRTY@","true")?"*":"");
- if (!strcmp("@GIT_HEAD_SHA1@", "GIT-NOTFOUND")) gitVersionString[0] = '\0';
+#define BUF_SIZE 100
+ static char gitVersionString[BUF_SIZE];
+ static bool init = false;
+ if (!init)
+ {
+ strncpy(gitVersionString,"@GIT_HEAD_SHA1@",BUF_SIZE);
+ strncat(gitVersionString,!strcmp("@GIT_IS_DIRTY@","true")?"*":"",BUF_SIZE);
+ if (!strcmp("@GIT_HEAD_SHA1@", "GIT-NOTFOUND")) gitVersionString[0] = '\0';
+ gitVersionString[BUF_SIZE-1]='\0';
+ init = true;
+ }
return gitVersionString;
}