[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
gEDA-cvs: CVS update: task.c
User: ahvezda
Date: 05/05/10 23:27:12
Modified: . task.c
Log:
Partially fixed seg fault when opening up schematics using gManager.
Revision Changes Path
1.7 +21 -14 eda/geda/devel/geda/src/task.c
(In the diff below, changes in quantity of whitespace are not shown.)
Index: task.c
===================================================================
RCS file: /home/cvspsrv/cvsroot/eda/geda/devel/geda/src/task.c,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -b -r1.6 -r1.7
--- task.c 22 Feb 2005 22:45:14 -0000 1.6
+++ task.c 11 May 2005 03:27:11 -0000 1.7
@@ -1,4 +1,4 @@
-/* $Id: task.c,v 1.6 2005/02/22 22:45:14 danmc Exp $ */
+/* $Id: task.c,v 1.7 2005/05/11 03:27:11 ahvezda Exp $ */
/*******************************************************************************/
/* */
@@ -70,7 +70,7 @@
static int NewIntCmd(const char *szFilename, struct Action_s *pAction);
static int NewExtCmd(const char *szFilename, struct Action_s *pAction);
static int NewImport(const char *szFilename, struct Action_s *pAction);
-static void StrReplace(char *szString, const char *szFrom, const char *szTo);
+static char* StrReplace(char *szString, const char *szFrom, const char *szTo);
@@ -411,10 +411,10 @@
return FAILURE;
}
strcpy(pTask->szValue, pAction->szCommand);
- StrReplace((char *) pTask->szValue, "%FILENAME%", (char *) FileGetName(szFilename));
- StrReplace((char *) pTask->szValue, "%FILEEXT%", (char *) FileGetExt(szFilename));
- StrReplace((char *) pTask->szValue, "%FILEDIR%", (char *) FileGetDir(szFilename));
- StrReplace((char *) pTask->szValue, "%FILEREL%", (char *) FileGetRel(szFilename));
+ pTask->szValue = StrReplace((char *) pTask->szValue, "%FILENAME%", (char *) FileGetName(szFilename));
+ pTask->szValue = StrReplace((char *) pTask->szValue, "%FILEEXT%", (char *) FileGetExt(szFilename));
+ pTask->szValue = StrReplace((char *) pTask->szValue, "%FILEDIR%", (char *) FileGetDir(szFilename));
+ pTask->szValue = StrReplace((char *) pTask->szValue, "%FILEREL%", (char *) FileGetRel(szFilename));
/* display message box if task blocking */
if (pTask->fFlags & TASK_BLOCKING)
@@ -479,10 +479,10 @@
return FAILURE;
}
strcpy(pTask->szValue, pAction->szImport);
- StrReplace((char *) pTask->szValue, "%FILENAME%", (char *) FileGetName(szFilename));
- StrReplace((char *) pTask->szValue, "%FILEEXT%", (char *) FileGetExt(szFilename));
- StrReplace((char *) pTask->szValue, "%FILEDIR%", (char *) FileGetDir(szFilename));
- StrReplace((char *) pTask->szValue, "%FILEREL%", (char *) FileGetRel(szFilename));
+ pTask->szValue = StrReplace((char *) pTask->szValue, "%FILENAME%", (char *) FileGetName(szFilename));
+ pTask->szValue = StrReplace((char *) pTask->szValue, "%FILEEXT%", (char *) FileGetExt(szFilename));
+ pTask->szValue = StrReplace((char *) pTask->szValue, "%FILEDIR%", (char *) FileGetDir(szFilename));
+ pTask->szValue = StrReplace((char *) pTask->szValue, "%FILEREL%", (char *) FileGetRel(szFilename));
pTask->pMenuItem = MenuWindowNew(pAction->szName);
pTask->Id = 0;
@@ -503,14 +503,14 @@
-static void StrReplace(char *szString, const char *szFrom, const char *szTo)
+static char* StrReplace(char *szString, const char *szFrom, const char *szTo)
{
char *szBegin, *szTemp;
int i;
szTemp = (void *) malloc(strlen(szString) + 1);
if (szTemp == NULL)
- return;
+ return NULL;
for (szBegin = strstr(szString, szFrom); szBegin != NULL; szBegin = strstr(szString, szFrom))
{
@@ -521,10 +521,17 @@
strcpy(szString, szTemp);
szString[i] = 0;
- realloc(szString, strlen(szString) + strlen(szTo) + strlen(szBegin + strlen(szFrom)) + 1);
+ /* realloc can change the modified pointer completely, so */
+ /* it needs to be assigned. Not doing this caused a nasty */
+ /* bug on some architectures/machines. */
+ szString = realloc(szString, strlen(szString) + strlen(szTo) + strlen(szBegin + strlen(szFrom)) + 1);
strcat(szString, szTo);
strcat(szString, szBegin + strlen(szFrom));
}
free((void *) szTemp);
+
+ /* You must return the pointer since realloc might have completely */
+ /* changed the pointer. */
+ return szString;
}