antirez / smallchat Goto Github PK
View Code? Open in Web Editor NEWA minimal programming example for a chat server
A minimal programming example for a chat server
How to support compiling on windows?
I use llvm-mingw or winlibs.
Unsafe use of return value of snprintf on line 346 can result in out of bounds read when length of nickname + length of name > 254.
https://github.com/antirez/smallchat/blob/main/smallchat.c#L346
from https://linux.die.net/man/3/snprintf
If the output was truncated due to this limit then the return value is the number of characters (excluding the terminating null byte) which would have been written to the final string if enough space had been available
Could fix by bounding msglen
variable to a max value of 256
.
if (msglen >= (int)sizeof(msg)) msglen = sizeof(msg)-1;
This sentence is redundant and can be deleted.
LMAO ><
I've read several issues and still don't understand how to use it.
In line 105 of smallchat-server.c, it should be wrapped in a pair of curly braces. Because the break on line 106 will now exit the loop directly.
if (Chat->maxclient == c->fd) {
/* Ooops, this was the max client set. Let's find what is
* the new highest slot used. */
int j;
for (j = Chat->maxclient-1; j >= 0; j--) {
if (Chat->clients[j] != NULL) Chat->maxclient = j;
break;
}
if (j == -1) Chat->maxclient = -1; // We no longer have clients.
}
should be changed to
if (Chat->maxclient == c->fd) {
/* Ooops, this was the max client set. Let's find what is
* the new highest slot used. */
int j;
for (j = Chat->maxclient - 1; j >= 0; j--) {
if (Chat->clients[j] != NULL) {
Chat->maxclient = j;
break;
}
}
if (j == -1) Chat->maxclient = -1; // We no longer have clients.
}
Thanks for your project. It is very nice for junior developers to learn network and C programming.One more question I think it is better if the "smallchat" can run or compile on windows. Because most of our junior developers program on windows ^_^!
Add license for the repository
I watched the video mentioned in the repo. I want to know his specific principles and philosophy of the code. Can anyone provide a python implementation of the code?
Brother, is there any usage documentation for this or how to deploy it?
In addition to functional code, testing, especially performance testing is also the point I want to learn about. For example, how much impact does concurrency and delay have on the program?
Mastering performance testing methods helps me quantitatively understand why write this way.
for (int j = 0; j <= Chat->maxclient; j++) {
if (Chat->clients[j]) FD_SET(j, &readfds);
}
why set FD_SET(j, &readfds);
not FD_SET(Chat->clients[j].fd, &readfds);
?
Line 142 in f6c3c9e
Depending on the configuration of someone's system, Linux will probably over-commit and not make malloc/realloc return a NULL pointer even if memory is full.
The default behavior is to over-commit if the memory request is not "unreasonable". Which basically means any small memory allocation request will return a pointer as if it allocated successfully, but then the program will segfault when trying to write to it, or more likely be killed by the out of memory manager before a write to it is attempted.
There's not really a great platform-independent solution, but I usually read /proc/meminfo and check the CommitLimit to check if an allocation request is too large. Edit: For this particular case, probably best to use MemAvailable
Hi, @antirez.
smallchat is an awesome project. I learned a lot from it.
What about add an exact open-source license to this repo?
I think this will allow people to better learn and participate in this interesting program.
Regards,
Xinfeng
Hi, How do I get it to run? need easy tutorial please.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.