Repository navigation
Closed
Labels
Language ServicebugfixedCheck the Milestone for the release in which the fix is or will be available.parser
Milestone
Description
Type: c/c++
Describe the bug
- OS and Version: macOS 10.14
- VS Code Version: 1.43.2
- C/C++ Extension Version: 0.26, 0.27
- Other extensions you installed (and if the issue persists after disabling them): none
- Does this issue involve using SSH remote to run the extension on a remote machine?: no
- A clear and concise description of what the bug is, including information about the workspace
I use "#ifdef...#elseif...#endif" statement to include header conditionally, the code is pass build and run well. But the squiggle(I think is clang-lint) is not recognize the marcos in the included header.
Additional context
// my code below:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#if defined(_WIN64) || defined(_WIN32)
#define WINDOWS
#endif
#ifdef WINDOWS
#include <winsock2.h>
typedef unsigned int socklen_t;
#else
#include <unistd.h>
#include <arpa/inet.h>
#include <sys/socket.h>
#include <sys/stat.h>
#define SOCKET_ERROR -1
#define INVALID_SOCKET -1
typedef struct sockaddr_in SOCKADDR_IN;
typedef struct sockaddr SOCKADDR;
typedef unsigned long long SOCKET;
#define closesocket(s) close(s)
#endif
#define PATH_LEN 1024
#define BUF_SIZE 1024 * 1024 * 100
void error_handling(char *message)
{
fputs(message, stderr);
fputc('\n', stderr);
exit(1);
}
int read_all(SOCKET sock, char *buf, int byte_len);
int64_t get_file_size(const char* filename)
{
struct stat statbuf;
stat(filename,&statbuf);
int64_t size = statbuf.st_size;
return size;
}
int main(int argc, char* argv[])
{
SOCKET serv_sock, clnt_sock;
char buf[PATH_LEN];
SOCKADDR_IN serv_addr, clnt_addr;
socklen_t addr_len;
char *file_buf = (char *) malloc(BUF_SIZE);
// signal(SIGPIPE, SIG_IGN);
if(argc < 2)
{
printf("Usage : %s <port> \n", argv[0]);
exit(1);
}
#ifdef WINDOWS
WSADATA wsa_data;
if(WSAStartup(MAKEWORD(2, 2), &wsa_data) == -1)
error_handling("Init Windows Socket Failed!");
#endif
if((serv_sock = socket(PF_INET, SOCK_STREAM, 0)) == INVALID_SOCKET)
error_handling("socket() error!");
memset(&serv_addr, 0, sizeof(serv_addr));
serv_addr.sin_family = AF_INET;
serv_addr.sin_addr.s_addr = htonl(INADDR_ANY);
serv_addr.sin_port = htons(atoi(argv[1]));
addr_len = sizeof(serv_addr);
if(bind(serv_sock, (SOCKADDR *) &serv_addr, addr_len) == SOCKET_ERROR)
error_handling("bind() error!");
if(listen(serv_sock, 5) == SOCKET_ERROR)
error_handling("listen() error!");
printf("Listening at < %s : %d > ...\n", inet_ntoa(serv_addr.sin_addr), ntohs(serv_addr.sin_port));
addr_len = sizeof(clnt_addr);
while((clnt_sock = accept(serv_sock, (SOCKADDR *) &clnt_addr, &addr_len)) != SOCKET_ERROR)
{
int byte_received = 0;
memset(buf, 0, PATH_LEN);
byte_received = read_all(clnt_sock, buf, 2);
if(byte_received == SOCKET_ERROR){
printf("read() error! [code: 0101]\n");
close(clnt_sock);
continue;
}
int package_len = *((short *) &buf);
byte_received = read_all(clnt_sock, &buf[byte_received], package_len - 2);
if(byte_received == SOCKET_ERROR){
printf("read() error! [code: 0102]\n");
close(clnt_sock);
continue;
}
// byte_received = package_len + 2;
char file_path[byte_received + 1];
memset(file_path, 0, sizeof(file_path));
memcpy(file_path, &buf[2], byte_received);
printf("Receive file name: %s\n", file_path);
FILE *fp = fopen((const char *)file_path,"rb");
if(fp == NULL)
{
printf("file not exists!\n");
printf("close %llu\n", clnt_sock);
closesocket(clnt_sock);
continue;
}
uint64_t file_size = get_file_size((const char *) file_path);
printf("Start sending file ...\n");
memset(buf, 0, PATH_LEN);
*((uint64_t *)buf) = file_size;
int bytes_sent = 0;
int bytes_len = sizeof(file_size);
while(bytes_sent < bytes_len) // send file size
{
int l = 0;
l = write(clnt_sock, &buf[bytes_sent], bytes_len - bytes_sent);
bytes_sent += l;
}
printf("File size: [%llu]\n", file_size);
while(!feof(fp)){ // send file
memset(file_buf, 0, BUF_SIZE);
bytes_len = fread(file_buf, 1, BUF_SIZE, fp);
bytes_sent = 0;
while((bytes_sent < bytes_len))
{
int l = bytes_len - bytes_sent;
bytes_sent += write(clnt_sock, &file_buf[bytes_sent], l);
}
printf("File sent: [%d]\n", bytes_sent);
}
free(file_buf);
fclose(fp);
closesocket(clnt_sock);
printf("close: %llu \n", clnt_sock);
}
printf("Server shutdown!");
closesocket(serv_sock);
#ifdef WINDOWS
WSACleanup();
#endif
return 0;
}
int read_all(SOCKET sock, char *buf, int byte_len) {
int byte_received = 0;
while(byte_received < byte_len)
{
int n = read(sock, &buf[byte_received], byte_len - byte_received);
if(n == SOCKET_ERROR || n == 0)
{
return -1;
}
byte_received += n;
}
return byte_received;
}Metadata
Metadata
Assignees
Labels
Language ServicebugfixedCheck the Milestone for the release in which the fix is or will be available.parser


Activity
sean-mcmanus commentedon Mar 26, 2020
I reproed the bug when I used the code in a C++ file on Mac, but it went I away when I used it in a C file (.c). I assume you want to compile it as a C, right? Make sure your files.associations setting doesn't have "*.C": "cpp" in it or your .c files will get treated as C++. Also, when you run C/C++: Log Diagnostics, you should not see any C++ references (i.e. in the standard version or system "Includes"). Let us know if you still have issues with this.
sean-mcmanus commentedon Mar 26, 2020
Oops, ignore my previous comment -- doing a reload window (with a C file) causes the squiggles to reappear. It also repros on Linux/WSL.
Colengms commentedon Sep 18, 2020
I've been able to reduce this somewhat to:
[-]c squiggle not recognize correctly with the #include statement in #ifdef...#elseif...#endif[/-][+]Incorrect squiggles after opening file, until file is edited[/+]Colengms commentedon Feb 10, 2021
Note that this does not appear to be a good candidate for repro'ing with isense_driver, as seemingly irrelevant edits to the file prevent the repro, and preprocessing the file incurs such changes. Moving all #include statements to a single header (so that perhaps it can be preprocessed, to remove the platform dependency), also prevents the repro. :/
sean-mcmanus commentedon Apr 17, 2021
Colen Garoutte-Carson (@Colengms) I got an isense_driver repro with #7270 ...so we can check if this bug is fixed when that other issue is fixed...and if not, get a isense_driver repro for this issue.
sean-mcmanus commentedon May 18, 2021
Fixed with https://github.com/microsoft/vscode-cpptools/releases/tag/1.4.0-insiders2