https://github.com/noyesno/awka
For the above repo, I got the following error when I try to compile it on macOS (gcc is just clang). I have no idea how to fix the problem according to the error message. It compiles fine on Linux.
I also tried the real gcc from Homebrew to compile the package. It also show the same error. How can I fix this problem on macOS?
$ ./configure
$ make
...
gcc -O -Dawka_LIBDIR=\"/usr/local/lib\" -Dawka_INCDIR=\"/usr/local/include\" -c -o print.o print.c
print.c:52:11: error: expected parameter declarator
int PROTO(sprintf, (char *, const char *,...)) ;
^
print.c:52:11: error: expected ')'
print.c:52:11: note: to match this '('
print.c:52:11: error: conflicting types for '__builtin___sprintf_chk'
int PROTO(sprintf, (char *, const char *,...)) ;
^
print.c:52:11: note: '__builtin___sprintf_chk' is a builtin with type 'int (char *, int, unsigned long, const char *, ...)'
3 errors generated.
make[1]: *** [<builtin>: print.o] Error 1
make[1]: Leaving directory '/private/tmp/awka/awka'
make: *** [Makefile:48: awka_exe] Error 2
I'm not going to spend ages on this, but it looks as though configure is gripping stdio.h looking for sprintf. It is unable to find it in the header, and so it adds the #define:
NO_SPRINTF_IN_STDIO
which it sets to 1, and uses it to add its own prototype for sprintf. Unfortunately, this appears to be a macro in this case, which replaces sprintf with '__builtin___sprintf_chk' instead (which has additional string length checks by the looks of it).
Possible solutions:
Comment out the line in print.c, and make sure stdio.h is included somewhere.
After running configure, search for where it defines NO_SPRINTF_IN_STDIO and set that var to 1?
Fix the configure to so a more rigorous test?
Related
I am trying to execute clang static analyzer (version 3.8) on some of the examples shown in its documentation (https://clang-analyzer.llvm.org/alpha_checks.html#security_alpha_checkers).
I created a small C program, as follows:
// note: requires alpha.security.taint check turned on.
void test() {
char s[] = "abc";
int x = getchar();
char c = s[x]; // warn: index is tainted
}
I am executing following command to analyze the above code:
/usr/lib/llvm-3.8/bin/scan-build -enable-checker alpha.security.taint.TaintPropagation clang -c example.c
The above command generates following error report:
scan-build: Using '/usr/lib/llvm-3.8/bin/clang' for static analysis
example.c:5:8: warning: Value stored to 'c' during its initialization is never read
char c = s[x]; // warn: index is tainted
^ ~~~~
1 warning generated.
scan-build: 1 bug found.
scan-build: Run 'scan-view /tmp/scan-build-2018-04-09-143549-15413-1' to examine bug reports.
I was expecting clang SA will complain about possible buffer overflow and buffer underflow at line 5, but it seems like taint analysis is not performed.
Can someone please suggest how to enable "alpha.security.taint" check?
To get a warning when using a tainted array index, you have to enable alpha.security.ArrayBoundV2 and alpha.security.taint.TaintPropagation:
$ ~/bld/llvm-project/build/bin/scan-build -enable-checker \
alpha.security.taint.TaintPropagation,alpha.security.ArrayBoundV2 \
gcc -c taint2.c
scan-build: Using '/home/scott/bld/llvm-project/build/bin/clang-9' for static analysis
taint2.c:6:10: warning: Value stored to 'c' during its initialization is never read
char c = s[x]; // warn: index is tainted
^ ~~~~
taint2.c:6:14: warning: Out of bound memory access (index is tainted)
char c = s[x]; // warn: index is tainted
^~~~
2 warnings generated.
scan-build: 2 bugs found.
scan-build: Run 'scan-view /tmp/scan-build-2019-09-11-204837-97704-1' to examine bug reports.
The TaintPropagation checker reports some things by itself, for example, passing tainted data to system(). It also exports tainting information for other checkers to use.
(I discovered this information primarily by looking at the source code, and secondarily through trial and error. The documentation isn't much help.)
https://stackoverflow.com/questions/43423803/document-classification-tool-in-c-compilation-error/43432470#43432470
In above link-
I get 3 errors after adding -fnested_functions as
gcc -c ./rainbow.c -fnested-functions process_wv.c test_file.c test_hdb_file.c
(The 3 files process_wv, test_file, test_hdb_file are removed from rainbow.c and added as seperate .c files to the directory now)
Output:-
./bow/libbow.h:1345:8: note: forward declaration of 'struct argp_child'
struct argp_child; /* forward declare this type */
^
./rainbow.c:655:5: error: function definition is not allowed here
{
^
./rainbow.c:663:8: warning: extra tokens at end of #endif directive [-Wextra-tokens]
#endif VPC_ONLY
^
//
./rainbow.c:734:3: warning: implicit declaration of function 'do_indexing' is invalid in C99
[-Wimplicit-function-declaration]
do_indexing ();
^
./rainbow.c:1175:49: warning: passing 'int *' to parameter of type 'socklen_t *' (aka 'unsigned int *') converts between
pointers to integer types with different sign [-Wpointer-sign]
newsockfd = accept(rainbow_sockfd, &cli_addr, &clilen);
^~~~~~~
/usr/include/sys/socket.h:681:69: note: passing argument to parameter here
int accept(int, struct sockaddr * __restrict, socklen_t * __restrict)
^
./rainbow.c:1586:30: error: use of undeclared identifier 'test_file'
bow_map_filenames_from_dir (test_file.c, 0, dir, "");
^
P.S Why is test_file.c unidentified (bow_map_filenames_from_dir in docnames.c) in rainbow.c even though they are inside the same bow-20020213 folder (Permissions are 755 for all)
Regards
taking this .. as a starting point:
./bow/libbow.h:1345:8: note: forward declaration of 'struct argp_child'
struct argp_child; /* forward declare this type */
The linked code has a major problem in not including all the header files (in any specific header file) that that specific header file needs.
BTW: the 'struct argp_child' is defined in the ./argp/argp.h header file.
I did the following:
downloaded all the files via the .zip facility
expanded the .zip file to ~/src_bow on my ubuntu linux computer
cd ~/src_bow
./configure
edited the resulting 'Makefile' to define the macro:
CFLAGS = -g -O -Wall -Wextra -std=gnu11 -Wimplicit
then entered:
make -f Makefile
The result was hundreds of warnings, notes and errors
Most of the compiler output messages were about syntax, incomplete struct definitions, ignored modifiers and conversions However, there were many many other problems exposed.
After fixing a couple of hundred of the problems I stopped.
To answer your question, the root of the problems you are having has to do with the appropriate header files not being included in other header files that need the information in the header files that are not being included in each header file.
I keep getting a uses gets() warning when trying to compile my interperater and nothing is outputing in the terminal. I changed gets() to fgets() as well but still its not outputing anything and gives me an error:
$ ./littleLisp
warning: this program uses gets(), which is unsafe.
5.000000
littleLisp.c:16:18: error: too few arguments to function call, expected 3, have 1
while (fgets(str) && strcmp(str, "")) {
~~~~~ ^
/usr/include/stdio.h:238:1: note: 'fgets' declared here
char *fgets(char * __restrict, int, FILE *);
^
1 error generated.
make: *** [littleLisp] Error 1
$ make littleLisp
cc littleLisp.c -o littleLisp
littleLisp.c:16:18: error: too few arguments to function call, expected 3, have 1
while (fgets(str) && strcmp(str, "")) {
~~~~~ ^
/usr/include/stdio.h:238:1: note: 'fgets' declared here
char *fgets(char * __restrict, int, FILE *);
^
1 error generated.
make: *** [littleLisp] Error 1
Any idea whats going on?
Here is the gist:
https://gist.github.com/rahul1346/8596118b834ecf41b1d9
As per the man page of fgets(), the syntax is
char *fgets(char *s, int size, FILE *stream);
so, a call to fgets() needs to have three arguments.
In your code, while (fgets(str)....., it has only one.
my code shows this warnings when compiling with "g++ -Wall -pedantic -Wno-long-long -c main.c". I have to compile in this mode, becouse its a homework and we have an application that corrects them and it uses this compile mode.
Error: invalid conversion from "void" to "int** " [-fpermissive]
Error: invalid conversion from "void" to "int* " [-fpermissive]
Error: invalid conversion from "void" to "main(int, char*)::VYSLEDEK" [-fpermissive]
the same errors continue as i realloc quite a lot in my program. I tried to change almost everything in that realloc, it is still the same.
Parts of the code :
struct VYSLEDEK
{
int sirka;
int vyska;
int zacatek_x;
int zacatek_y;
int soucet;
} *vysledek;
int **matice,**soucty;
.....
matice=(int**)malloc(1*sizeof(int*));
matice[0]=(int*)malloc(1*sizeof(int));
soucty=(int**)malloc(1*sizeof(int*));
soucty[0]=(int*)malloc(1*sizeof(int));
.....
1. matice=realloc(matice,naalokovano*2*sizeof(int*));
2. soucty=realloc(soucty,naalokovano*2*sizeof(int*));
.....
for (i=0;i<(naalokovano*2);i++)
{
3. matice[i]=realloc(matice[i],sizeof(int));
4. soucty[i]=realloc(soucty[i],sizeof(int*));
};
.....
5. vysledek=realloc(vysledek,vysledku*sizeof(struct VYSLEDEK*));
Thank you for your help.
You already did cast the result of malloc to the right type. Do the same for the realloc calls, too.
BTW: Don’t complain that they force you to switch on the warnings. I think it’s the most sensible thing to do by default, I always use at least -Wall -Werror.
I am trying to compile a .cpp-file which uses a matrix-library. The library-files libnewmat.a and libnewmat.so are in the path /usr/lib64 . The include-files are in path /usr/include/newmat , so I tried (several ways) to compile i.e. with:
g++ -I/usr/include -L/usr/lib64 -lnewmat new.cpp -o new3
but the compiler doesn't find the library. The content of the .cpp is:
#include <iostream>
#include <newmat/newmat.h>
#include <newmat/newmatio.h>
using namespace std;
int main()
{
Matrix A(2,2);
Real b[] = {1,2,3,4};
A << b;
cout << A << endl;
return 0;
}
The compiler says:
test.cpp: In function ‘int main()’:
test.cpp:9: error: ‘Matrix’ was not declared in this scope
test.cpp:9: error: expected ‘;’ before ‘A’
test.cpp:10: error: ‘Real’ was not declared in this scope
test.cpp:10: error: expected ‘;’ before ‘b’
test.cpp:11: error: ‘A’ was not declared in this scope
test.cpp:11: error: ‘b’ was not declared in
this scope
Could You provide me with the correct c++ code, or the correct command line instruction?
Thanks, Kepler
If you recently installed this library yourself you probably need to run sudo ldconfig to load the so into the linker cache.
EDIT: As Kevin said not a linking error that you're getting.
Perhaps it's a name space issue?
using namespace NEWMAT;
according to this: http://www.robertnz.net/nm10.htm#namesp
This isn't a library problem - it's a compiler problem - it can't find any definition for Matrix (probably in your include files, but we can't determine that with the information given)
[edit]
Ascertain if your classes in the include files are being referenced correctly
[/edit]