Fix crash upon error.

This commit is contained in:
carl 2019-03-25 00:09:42 +08:00
parent 98d8505c6e
commit a915b76300

View file

@ -355,13 +355,13 @@ char* stringdup(const char* s)
char* getackhome(void) char* getackhome(void)
{ {
char *value = stringdup(getenv("ACK_HOME")); char *value = getenv("ACK_HOME");
if (value == NULL) if (value == NULL)
{ {
#ifndef EM_DIR #ifndef EM_DIR
panic("ACK_HOME must be set."); panic("ACK_HOME must be set.");
#else #else
return stringdup(EM_DIR); return EM_DIR;
#endif #endif
} }
return value; return value;
@ -383,12 +383,12 @@ int main(int argc, char *argv[])
char *INCLUDE = NULL; char *INCLUDE = NULL;
int compile_cnt = 0; int compile_cnt = 0;
ackhome = getackhome(); ackhome = stringdup(getackhome());
if (ackhome == NULL) if (ackhome == NULL)
{ {
panic("ACK_HOME Environment variable is not set."); panic("ACK_HOME Environment variable is not set.");
} }
tmpdir = sys_gettmpdir(); tmpdir = stringdup(sys_gettmpdir());
if (tmpdir == NULL) if (tmpdir == NULL)
{ {
panic("TMPDIR Environment variable is not set."); panic("TMPDIR Environment variable is not set.");
@ -478,6 +478,9 @@ int main(int argc, char *argv[])
case 'M': /* use other compiler (for testing) */ case 'M': /* use other compiler (for testing) */
strcpy(COMP, str + 2); strcpy(COMP, str + 2);
break; break;
case 'P': /* use other cpp (for testing) */
strcpy(CPP, str + 2);
break;
case 's': /* strip */ case 's': /* strip */
if (str[2] == '\0') if (str[2] == '\0')
{ {
@ -663,6 +666,10 @@ int main(int argc, char *argv[])
runvec(call, (char *) 0);*/ runvec(call, (char *) 0);*/
cleanup(tmp_file); cleanup(tmp_file);
} }
if ((LDFILES.al_argc == 0) && (SRCFILES.al_argc==0))
{
panic("No input source files or input object files specified.");
}
exit(RET_CODE); exit(RET_CODE);
} }