]> git.mxchange.org Git - flightgear.git/commitdiff
Use auto_ptr when calling SGSoundSample
authorehofman <ehofman>
Mon, 19 Oct 2009 14:10:31 +0000 (14:10 +0000)
committerTim Moore <timoore@redhat.com>
Mon, 19 Oct 2009 22:00:08 +0000 (00:00 +0200)
src/ATCDCL/ATC.cxx
src/Sound/beacon.cxx
src/Sound/morse.cxx

index 92568edc56725be3de1cc605a47ed24685a6011a..480257bc71acb74e186bea2a0d0290b611aca5b5 100644 (file)
@@ -237,8 +237,10 @@ void FGATC::Render(string& msg, const float volume,
 // >>> Beware: must pass a (new) object to the (add) method,
 // >>> because the (remove) method is going to do a (delete)
 // >>> whether that's what you want or not.
+                               std::auto_ptr<unsigned char> ptr;
+                                ptr.reset((unsigned char*) buf.c_str());
                                SGSoundSample *simple = 
-                               new SGSoundSample((unsigned char*) buf.c_str(),  buf.length(), 8000);
+                                   new SGSoundSample(ptr,  buf.length(), 8000);
                                // TODO - at the moment the volume can't be changed 
                                // after the transmission has started.
                                simple->set_volume(volume);
index 9b5f353afb59f7ce90ef2c46dc61b0f9ece3fa63..6de5f46242ca16649f2be8242555e3d52d40d107 100644 (file)
@@ -41,9 +41,9 @@ bool FGBeacon::init() {
     int len;
     unsigned char *ptr;
 
-    unsigned char *inner_buf = new unsigned char[ INNER_SIZE ] ;
-    unsigned char *middle_buf = new unsigned char[ MIDDLE_SIZE ] ;
-    unsigned char *outer_buf = new unsigned char[ OUTER_SIZE ] ;
+    std::auto_ptr<unsigned char>inner_buf( new unsigned char[ INNER_SIZE ] );
+    std::auto_ptr<unsigned char>middle_buf( new unsigned char[ MIDDLE_SIZE ] );
+    std::auto_ptr<unsigned char>outer_buf( new unsigned char[ OUTER_SIZE ] );
 
     // Make inner marker beacon sound
     len= (int)(INNER_DIT_LEN / 2.0 );
@@ -51,7 +51,7 @@ bool FGBeacon::init() {
     make_tone( inner_dit, INNER_FREQ, len, INNER_DIT_LEN,
               TRANSITION_BYTES );
 
-    ptr = inner_buf;
+    ptr = inner_buf.get();
     for ( i = 0; i < 6; ++i ) {
        memcpy( ptr, inner_dit, INNER_DIT_LEN );
        ptr += INNER_DIT_LEN;
@@ -73,7 +73,7 @@ bool FGBeacon::init() {
         make_tone( middle_dah, MIDDLE_FREQ, len, MIDDLE_DAH_LEN,
                    TRANSITION_BYTES );
 
-        ptr = middle_buf;
+        ptr = middle_buf.get();
         memcpy( ptr, middle_dit, MIDDLE_DIT_LEN );
         ptr += MIDDLE_DIT_LEN;
         memcpy( ptr, middle_dah, MIDDLE_DAH_LEN );
@@ -88,7 +88,7 @@ bool FGBeacon::init() {
         make_tone( outer_dah, OUTER_FREQ, len, OUTER_DAH_LEN,
                    TRANSITION_BYTES );
            
-        ptr = outer_buf;
+        ptr = outer_buf.get();
         memcpy( ptr, outer_dah, OUTER_DAH_LEN );
         ptr += OUTER_DAH_LEN;
         memcpy( ptr, outer_dah, OUTER_DAH_LEN );
index a562732888c8c99044bcc021a7b7d408c416c4e0..c9195e78d7a5672b6d949488fcd80b0f1ed28703 100644 (file)
@@ -219,10 +219,10 @@ SGSoundSample *FGMorse::make_ident( const string& id, const int freq ) {
     length += 2 * SPACE_SIZE;
 
     // 2. Allocate space for the message
-    unsigned char *buffer = new unsigned char[length];
+    std::auto_ptr<unsigned char>buffer( new unsigned char[length] );
 
     // 3. Assemble the message;
-    unsigned char *buf_ptr = buffer;
+    unsigned char *buf_ptr = buffer.get();
 
     for ( i = 0; i < (int)id.length(); ++i ) {
        if ( idptr[i] >= 'A' && idptr[i] <= 'Z' ) {