这是有关要提供给misra.py cppcheck应用程序的规则文件的预期布局和内容的一般问题。
位于github上的cppcheck源: source cppcheck
我有多种想法?
***** Client side *****
-- call client with IP of server as arg --
#define PORT "3490" // the port client will be connecting to
int main(int argc, char *argv[])
{
int sockfd, numbytes;
unsigned char buf[MAXDATASIZE];
struct addrinfo hints, *servinfo, *p;
int rv;
char s[INET6_ADDRSTRLEN];
memset(&hints, 0, sizeof hints);
hints.ai_family = AF_UNSPEC;
hints.ai_socktype = SOCK_STREAM;
if ((rv = getaddrinfo(argv[1], PORT, &hints, &servinfo)) != 0) {
fprintf(stderr, "getaddrinfo: %s\n", gai_strerror(rv));
return 1;
}
// loop through all the results and connect to the first we can
for(p = servinfo; p != NULL; p = p->ai_next) {
if ((sockfd = socket(p->ai_family, p->ai_socktype,
p->ai_protocol)) == -1) {
continue;
}
if (connect(sockfd, p->ai_addr, p->ai_addrlen) == -1) {
close(sockfd);
continue;
}
break;
}
inet_ntop(p->ai_family, get_in_addr((struct sockaddr *)p->ai_addr), s, sizeof s);
printf("client: connecting to %s\n", s);
freeaddrinfo(servinfo);
if ((numbytes = recv(sockfd, buf, MAXDATASIZE-1, 0)) == -1) {
exit(1);
}
//deserialize and output data -- omitted
return 0;
}
***** Server side *****
int main(void)
{
srand (time(NULL));
mydata md0; //data structure that will be sent
//write members of md0 -- omitted
unsigned char buf[MAXDATASIZE],*ptr;
ptr = Serialize_mydata(buf,&md0);
int sockfd, new_fd; // listen on sock_fd, new connection on new_fd
struct addrinfo hints, *servinfo, *p;
struct sockaddr_storage their_addr; // connector's address information
socklen_t sin_size;
struct sigaction sa;
int yes=1;
char s[INET6_ADDRSTRLEN];
int rv;
memset(&hints, 0, sizeof hints);
hints.ai_family = AF_UNSPEC;
hints.ai_socktype = SOCK_STREAM;
hints.ai_flags = AI_PASSIVE; // use my IP
if ((rv = getaddrinfo(NULL, PORT, &hints, &servinfo)) != 0) {
fprintf(stderr, "getaddrinfo: %s\n", gai_strerror(rv));
return 1;
}
// loop through all the results and bind to the first we can
for(p = servinfo; p != NULL; p = p->ai_next) {
if ((sockfd = socket(p->ai_family, p->ai_socktype,p->ai_protocol)) == -1) {
perror("server: socket");
continue;
}
if (setsockopt(sockfd, SOL_SOCKET, SO_REUSEADDR, &yes, sizeof(int)) == -1) {
exit(1);
}
if (bind(sockfd, p->ai_addr, p->ai_addrlen) == -1) {
close(sockfd);
continue;
}
break;
}
freeaddrinfo(servinfo); // all done with this structure
if (listen(sockfd, BACKLOG) == -1) {
exit(1);
}
sa.sa_handler = sigchld_handler; // reap all dead processes
sigemptyset(&sa.sa_mask);
sa.sa_flags = SA_RESTART;
if (sigaction(SIGCHLD, &sa, NULL) == -1) {
exit(1);
}
printf("server: waiting for connections...\n");
while(1) { // main accept() loop
sin_size = sizeof their_addr;
new_fd = accept(sockfd, (struct sockaddr *)&their_addr, &sin_size);
if (new_fd == -1) {
continue;
}
inet_ntop(their_addr.ss_family, get_in_addr((struct sockaddr *)&their_addr), s, sizeof s);
printf("server: got connection from %s\n", s);
if (!fork()) { // this is the child process
close(sockfd); // child doesn't need the listener
if (send(new_fd, buf, ptr - buf, 0) == -1)
close(new_fd);
exit(0);
}
close(new_fd); // parent doesn't need this
}
return 0;
}
还是
Appendix A Summary of guidelines
Rule 1.1
Rule text description
在MISRA标准中,他们谈论DIR 1.1规则1.1 必需的,强制性的,建议性的。
pdftotext并使用以下方法 link to misra rule generator 我只得到一个目录1.1的输出
答案 0 :(得分:0)
规则文件的格式在位于 cppcheck 的 GitHub 存储库中的 misra.py 插件文件的使用/帮助输出中列出。 python misra.py --help
输出用法部分,尽管输出中的换行符在 git bash 和 Windows 命令提示符中弄乱了,对我来说不太有用。实际帮助文本在 misra.py 文件中的格式很好:
Format:
<..arbitrary text..>
Appendix A Summary of guidelines
Rule 1.1
Rule text for 1.1
Rule 1.2
Rule text for 1.2
<...>
我还尝试通过问题中链接的 misra rule generator 生成规则文件。在 Windows 中使用 git bash(它具有脚本所需的 pdftotext
二进制文件)运行生成器时,我也只得到包含单个条目的输出文件(Dir 1.1)。在 Ubuntu 18.04 中运行生成器,它会生成一个包含大部分 Misra 规则和指令的大型输出文件。 Git bash 的 pdftotext
报告它的版本为 4.00,而 Ubuntu 中的 pdftotext
报告为 0.62.0。 pdftotext
在 Git Bash 和 Ubuntu 中生成的输出非常不同,并且 Misra 规则生成器脚本仅适用于 Ubuntu pdftotext
的输出在我的情况下。
我还注意到 Misra 规则生成器有一个错误,它会覆盖具有相同编号的规则和指令。输出将不会同时包含 Dir 1.1 和 Rule 1.1,由于此处的字典处理错误 cppcheck-misra-parsetexts.py
,解析的最后一个将覆盖前者