PUD: replace some memcpy's by simple assignments
authorFerry Huberts <ferry.huberts@pelagic.nl>
Tue, 6 Mar 2012 13:16:19 +0000 (14:16 +0100)
committerFerry Huberts <ferry.huberts@pelagic.nl>
Tue, 6 Mar 2012 13:17:15 +0000 (14:17 +0100)
Signed-off-by: Ferry Huberts <ferry.huberts@pelagic.nl>
lib/pud/src/configuration.c
lib/pud/src/dedup.c
lib/pud/src/gpsConversion.c
lib/pud/src/posAvg.c
lib/pud/src/receiver.c

index bf7c1bf..5b8c201 100644 (file)
@@ -619,8 +619,7 @@ int addRxAllowedSourceIpAddress(const char *value, void *data __attribute__ ((un
                        return true;
                }
 
-               memcpy(&rxAllowedSourceIpAddresses[rxAllowedSourceIpAddressesCount],
-                               &addr, sizeof(addr));
+               rxAllowedSourceIpAddresses[rxAllowedSourceIpAddressesCount] = addr;
                rxAllowedSourceIpAddressesCount++;
        }
 
index 773af2a..9f213c7 100644 (file)
@@ -125,12 +125,10 @@ void addToDeDup(DeDupList * deDupList, union olsr_message *olsrMessage) {
        memset(newEntry, 0, sizeof(DeDupEntry));
        if (olsr_cnf->ip_version == AF_INET) {
                newEntry->seqno = olsrMessage->v4.seqno;
-               memcpy(&newEntry->originator.v4, &olsrMessage->v4.originator,
-                               sizeof(newEntry->originator.v4));
+               newEntry->originator.v4.s_addr = olsrMessage->v4.originator;
        } else {
                newEntry->seqno = olsrMessage->v6.seqno;
-               memcpy(&newEntry->originator.v6, &olsrMessage->v6.originator,
-                               sizeof(newEntry->originator.v6));
+               newEntry->originator.v6 = olsrMessage->v6.originator;
        }
 
        deDupList->newestEntryIndex = incomingIndex;
index f548a7b..75a8b80 100644 (file)
@@ -342,8 +342,7 @@ unsigned int gpsToOlsr(nmeaINFO *nmeaInfo, union olsr_message *olsrMessage,
                olsrMessage->v4.olsr_msgtype = PUD_OLSR_MSG_TYPE;
                olsrMessage->v4.olsr_vtime = reltime_to_me(validityTime * 1000);
                /* message->v4.olsr_msgsize at the end */
-               memcpy(&olsrMessage->v4.originator, &olsr_cnf->main_addr,
-                               olsr_cnf->ipsize);
+               olsrMessage->v4.originator = olsr_cnf->main_addr.v4.s_addr;
                olsrMessage->v4.ttl = getOlsrTtl();
                olsrMessage->v4.hopcnt = 0;
                olsrMessage->v4.seqno = htons(get_msg_seqno());
@@ -358,8 +357,7 @@ unsigned int gpsToOlsr(nmeaINFO *nmeaInfo, union olsr_message *olsrMessage,
                olsrMessage->v6.olsr_msgtype = PUD_OLSR_MSG_TYPE;
                olsrMessage->v6.olsr_vtime = reltime_to_me(validityTime * 1000);
                /* message->v6.olsr_msgsize at the end */
-               memcpy(&olsrMessage->v6.originator, &olsr_cnf->main_addr,
-                               olsr_cnf->ipsize);
+               olsrMessage->v6.originator = olsr_cnf->main_addr.v6;
                olsrMessage->v6.ttl = getOlsrTtl();
                olsrMessage->v6.hopcnt = 0;
                olsrMessage->v6.seqno = htons(get_msg_seqno());
index 132ce96..a29881b 100644 (file)
@@ -448,9 +448,7 @@ static void updatePositionAverageFromCumulative(
        dump_nmeaInfo(&positionAverageList->positionAverage.nmeaInfo, "updatePositionAverageFromCumulative: positionAverageList->positionAverage (before)");
 #endif /* PUD_DUMP_AVERAGING */
 
-       memcpy(&positionAverageList->positionAverage,
-                       &positionAverageList->positionAverageCumulative,
-                       sizeof(positionAverageList->positionAverage));
+       positionAverageList->positionAverage = positionAverageList->positionAverageCumulative;
 
        /* smask: use from cumulative average */
 
index e67d8af..f150246 100644 (file)
@@ -210,7 +210,7 @@ static void txToAllOlsrInterfaces(TimedTxInterface interfaces) {
        pu_size = gpsToOlsr(&transmitGpsInformation.txPosition.nmeaInfo, pu, txBufferBytesFree,
                        ((state.externalState == MOVING) ? getUpdateIntervalMoving() : getUpdateIntervalStationary()));
        txBufferBytesUsed += pu_size;
-       memcpy(&gateway, &transmitGpsInformation.txGateway, olsr_cnf->ipsize);
+       gateway = transmitGpsInformation.txGateway;
 
        transmitGpsInformation.updated = false;
        (void) pthread_mutex_unlock(&transmitGpsInformation.mutex);
@@ -299,6 +299,7 @@ static void txToAllOlsrInterfaces(TimedTxInterface interfaces) {
                                        (state.externalState == MOVING) ?
                                                        getUplinkUpdateIntervalMoving() : getUplinkUpdateIntervalStationary());
 
+                       /* really need 2 memcpy's here because of olsr_cnf->ipsize */
                        memcpy(cl_originator, &olsr_cnf->main_addr, olsr_cnf->ipsize);
                        memcpy(cl_clusterLeader, &gateway, olsr_cnf->ipsize);
 
@@ -720,8 +721,8 @@ bool receiverUpdateGpsInformation(unsigned char * rxBuffer, size_t rxCount) {
        }
 
        (void) pthread_mutex_lock(&transmitGpsInformation.mutex);
-       memcpy(&txPosition, &transmitGpsInformation.txPosition, sizeof(PositionUpdateEntry));
-       memcpy(&txGateway, &transmitGpsInformation.txGateway, olsr_cnf->ipsize);
+       txPosition = transmitGpsInformation.txPosition;
+       txGateway = transmitGpsInformation.txGateway;
        (void) pthread_mutex_unlock(&transmitGpsInformation.mutex);
 
        /* parse all NMEA strings in the rxBuffer into the incoming entry */
@@ -865,8 +866,8 @@ bool receiverUpdateGpsInformation(unsigned char * rxBuffer, size_t rxCount) {
 
        if ((state.externalState == MOVING) || updateTransmitGpsInformation) {
                (void) pthread_mutex_lock(&transmitGpsInformation.mutex);
-               memcpy(&transmitGpsInformation.txPosition.nmeaInfo, &posAvgEntry->nmeaInfo, sizeof(nmeaINFO));
-               memcpy(&transmitGpsInformation.txGateway, bestGateway, olsr_cnf->ipsize);
+               transmitGpsInformation.txPosition.nmeaInfo = posAvgEntry->nmeaInfo;
+               transmitGpsInformation.txGateway = *bestGateway;
                transmitGpsInformation.updated = true;
                (void) pthread_mutex_unlock(&transmitGpsInformation.mutex);
 
@@ -924,7 +925,7 @@ bool startReceiver(void) {
        }
 
        nmea_zero_INFO(&transmitGpsInformation.txPosition.nmeaInfo);
-       memcpy(&transmitGpsInformation.txGateway, &olsr_cnf->main_addr, olsr_cnf->ipsize);
+       transmitGpsInformation.txGateway = olsr_cnf->main_addr;
        transmitGpsInformation.updated = false;
 
        state.internalState = MOVING;
@@ -964,7 +965,7 @@ void stopReceiver(void) {
 
        transmitGpsInformation.updated = false;
        nmea_zero_INFO(&transmitGpsInformation.txPosition.nmeaInfo);
-       memcpy(&transmitGpsInformation.txGateway, &olsr_cnf->main_addr, olsr_cnf->ipsize);
+       transmitGpsInformation.txGateway = olsr_cnf->main_addr;
 
        nmea_parser_destroy(&nmeaParser);