-
Notifications
You must be signed in to change notification settings - Fork 2
9src/cc: pcc produces $O.out, keeps .6 objects; use basename for prog… #135
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -60,16 +60,19 @@ char *searchlib(char *, char*); | |
| void | ||
| main(int argc, char *argv[]) | ||
| { | ||
| char *s, *suf, *ccpath, *lib; | ||
| char *s, *suf, *ccpath, *lib, *prog; | ||
| char *oname, *objext; | ||
| int haveoname = 0; | ||
| int i, cppn, ccn; | ||
| Objtype *ot; | ||
|
|
||
| ot = findoty(); | ||
| oname = "a.out"; | ||
| /* cc produces .o (for configure compat); pcc uses arch-native .$O */ | ||
| objext = (strcmp(argv[0], "cc") == 0) ? "o" : ot->o; | ||
| prog = utfrrune(argv[0], '/'); | ||
| prog = prog ? prog+1 : argv[0]; | ||
| /* cc: POSIX mode (.o objects, a.out output, clean up intermediates) | ||
| * pcc: Plan9 native mode (.$O objects, $O.out output, keep objects) */ | ||
| objext = (strcmp(prog, "cc") == 0) ? "o" : ot->o; | ||
| oname = (strcmp(prog, "cc") == 0) ? "a.out" : smprint("%s.out", ot->o); | ||
|
Comment on lines
+74
to
+75
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The if(strcmp(prog, "cc") == 0){
objext = "o";
oname = "a.out";
}else{
objext = ot->o;
if((oname = smprint("%s.out", ot->o)) == NULL){
fprint(2, "out of memory\n");
exits("mem");
}
} |
||
| append(&cpp, "cpp"); | ||
| append(&cpp, "-D__STDC__=1"); /* ANSI says so */ | ||
| append(&cpp, "-D_POSIX_SOURCE="); | ||
|
|
@@ -221,8 +224,8 @@ main(int argc, char *argv[]) | |
| append(&ld, objs.strings[i]); | ||
| append(&ld, smprint("/%s/lib/ape/libap.a", ot->name)); | ||
| doexec(smprint("/bin/%s", ot->ld), &ld); | ||
| if(objs.n == 1) | ||
| remove(objs.strings[0]); | ||
| if(objs.n == 1 && strcmp(objext, "o") == 0) | ||
| remove(objs.strings[0]); /* cc mode only: clean up .o intermediate */ | ||
| if(gflag) { | ||
| /* post-link: convert a.out + .dwtypes sidecars to ELF64 */ | ||
| memset(&dw2elf_cmd, 0, sizeof dw2elf_cmd); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If
argcis 0,argv[0]will beNULL, causingutfrruneto dereference a null pointer and crash. Whileargcis usually at least 1 in standard execution environments, adding a check forargv[0]orargcbefore processing the program name is a safer practice to ensure robustness.