Skip to content

Commit

Permalink
Merge pull request #33 from stevenengler/memmove
Browse files Browse the repository at this point in the history
Change 'g_memmove' to 'memmove'
  • Loading branch information
stevenengler authored May 12, 2022
2 parents e5cd207 + 2334a4b commit 53332cd
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 19 deletions.
4 changes: 2 additions & 2 deletions src/tgen-stream.c
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,7 @@ static gsize _tgenstream_readBuffered(TGenStream* stream, guchar* buffer, gsize
if(stream->recv.buffer->len <= limit) {
/* take all of the recv buffer */
gsize amount = stream->recv.buffer->len;
g_memmove(buffer, stream->recv.buffer->str, amount);
memmove(buffer, stream->recv.buffer->str, amount);

/* don't need the recv buffer any more */
g_string_free(stream->recv.buffer, TRUE);
Expand All @@ -431,7 +431,7 @@ static gsize _tgenstream_readBuffered(TGenStream* stream, guchar* buffer, gsize
return amount;
} else {
/* we already have more buffered than the caller wants */
g_memmove(buffer, stream->recv.buffer->str, limit);
memmove(buffer, stream->recv.buffer->str, limit);

/* we want to keep the remaining bytes that we did not return */
GString* newBuffer = g_string_new(&stream->recv.buffer->str[limit]);
Expand Down
34 changes: 17 additions & 17 deletions src/tgen-transport.c
Original file line number Diff line number Diff line change
Expand Up @@ -697,11 +697,11 @@ static TGenEvent _tgentransport_sendSocksAuth(TGenTransport* transport) {

gchar buffer[255+255+3] = {0};

g_memmove(&buffer[0], "\x01", 1);
g_memmove(&buffer[1], &userlen, 1);
g_memmove(&buffer[2], user, userlen);
g_memmove(&buffer[2+userlen], &passlen, 1);
g_memmove(&buffer[3+userlen], pass, passlen);
memmove(&buffer[0], "\x01", 1);
memmove(&buffer[1], &userlen, 1);
memmove(&buffer[2], user, userlen);
memmove(&buffer[2+userlen], &passlen, 1);
memmove(&buffer[3+userlen], pass, passlen);

/* use g_string_new_len to make sure the NULL gets written */
transport->socksBuffer = g_string_new_len(&buffer[0], (gssize)3+userlen+passlen);
Expand Down Expand Up @@ -829,10 +829,10 @@ static TGenEvent _tgentransport_sendSocksRequest(TGenTransport* transport) {
gchar buffer[nameLength+8];
memset(buffer, 0, nameLength+8);

g_memmove(&buffer[0], "\x05\x01\x00\x03", 4);
g_memmove(&buffer[4], &nameLength, 1);
g_memmove(&buffer[5], name, nameLength);
g_memmove(&buffer[5+nameLength], &port, 2);
memmove(&buffer[0], "\x05\x01\x00\x03", 4);
memmove(&buffer[4], &nameLength, 1);
memmove(&buffer[5], name, nameLength);
memmove(&buffer[5+nameLength], &port, 2);

/* use g_string_new_len to make sure the NULL gets written */
transport->socksBuffer = g_string_new_len(&buffer[0], nameLength+7);
Expand All @@ -845,9 +845,9 @@ static TGenEvent _tgentransport_sendSocksRequest(TGenTransport* transport) {

gchar buffer[16] = {0};

g_memmove(&buffer[0], "\x05\x01\x00\x01", 4);
g_memmove(&buffer[4], &ip, 4);
g_memmove(&buffer[8], &port, 2);
memmove(&buffer[0], "\x05\x01\x00\x01", 4);
memmove(&buffer[4], &ip, 4);
memmove(&buffer[8], &port, 2);

transport->socksBuffer = g_string_new_len(&buffer[0], 10);
g_assert(transport->socksBuffer->len == 10);
Expand Down Expand Up @@ -890,7 +890,7 @@ static TGenEvent _tgentransport_sendSocksRequest(TGenTransport* transport) {
static TGenEvent _tgentransport_receiveSocksResponseTypeName(TGenTransport* transport) {
/* case 4b - domain name mode */
guint8 nameLength = 0;
g_memmove(&nameLength, &transport->socksBuffer->str[0], 1);
memmove(&nameLength, &transport->socksBuffer->str[0], 1);

/* len is left over from prev read - now we want to read the name+port so
* that we have the full len+name+port */
Expand All @@ -908,8 +908,8 @@ static TGenEvent _tgentransport_receiveSocksResponseTypeName(TGenTransport* tran
memset(namebuf, 0, nameLength+1);
in_port_t socksBindPort = 0;

g_memmove(namebuf, &transport->socksBuffer->str[1], nameLength);
g_memmove(&socksBindPort, &transport->socksBuffer->str[1+nameLength], 2);
memmove(namebuf, &transport->socksBuffer->str[1], nameLength);
memmove(&socksBindPort, &transport->socksBuffer->str[1+nameLength], 2);

g_string_free(transport->socksBuffer, TRUE);
transport->socksBuffer = NULL;
Expand Down Expand Up @@ -967,8 +967,8 @@ static TGenEvent _tgentransport_receiveSocksResponseTypeIPv4(TGenTransport* tran
/* check if they want us to connect elsewhere */
in_addr_t socksBindAddress = 0;
in_port_t socksBindPort = 0;
g_memmove(&socksBindAddress, &transport->socksBuffer->str[0], 4);
g_memmove(&socksBindPort, &transport->socksBuffer->str[4], 2);
memmove(&socksBindAddress, &transport->socksBuffer->str[0], 4);
memmove(&socksBindPort, &transport->socksBuffer->str[4], 2);

g_string_free(transport->socksBuffer, TRUE);
transport->socksBuffer = NULL;
Expand Down

0 comments on commit 53332cd

Please sign in to comment.