473,806 Members | 2,248 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Works on Windows but not on HPUX, Help Please

Hi,

This code works fine on win and linux but not on hpux. All is compiled
with gcc. Can anyone help please?

/*************** *************** *************** *************** *************** **/
/*
*/
/* encrypt
*/
/*
*/
/*************** *************** *************** *************** *************** **/
/* Description: Utility function that simply encrypts a string. Used
for */
/* simple password storage in the config file.
*/
/*
*/
/*************** *************** *************** *************** *************** **/
void encrypt(char str[],int key)
{
unsigned int i;
for(i=0;i<strle n(str);++i)
{
str[i] = str[i] - key;
}
}

/*************** *************** *************** *************** *************** **/
/*
*/
/* decrypt
*/
/*
*/
/*************** *************** *************** *************** *************** **/
/* Description: Utility function that simply decrypts a string. Used
for */
/* simple password storage in the config file.
*/
/*
*/
/*************** *************** *************** *************** *************** **/
void decrypt(char str[],int key)
{
unsigned int i;
for(i=0;i<strle n(str);++i)
{
str[i] = str[i] + key;
}
}
The decrypt function even shortens the length, which as you can see,
shouldnt happen and doesnt on other OSs

Any help would be great, thanks
Kind regards
Danny

Jun 27 '06
10 1867
Walter Roberson wrote:

In article <44***********@ mindspring.com> ,
pete <pf*****@mindsp ring.com> wrote:
In article <11************ *********@i40g2 000cwc.googlegr oups.com>,
Smurff <da***********@ gmail.com> wrote:void encrypt(char str[],int key)
>{
> unsigned int i;
> for(i=0;i<strle n(str);++i)
> {
> str[i] = str[i] - key;
> }
>}
If the value of key is INT_MIN,
that would cause undefined behavior in encrypt.


Hmmm, do I read C89 correctly that the char str[i] will be
converted to an int, not an unsigned int, even if char is unsigned,
with the exception of the case where sizeof char == sizeof int
[that being the case where the value of an unsigned char might
not fit within a signed int] ?


Yes.
unsigned short can also be promoted to signed int.
Code which attempts to increment either unsigned short
or unsigned char until roll over,
without checking first to make sure that signed int
doesn't have the same number of value bits,
is undefined.
C89 3.2.1.1 Characters and Integers

Assuming that all values of char will fit within an int:

- if char is unsigned then its minimum value would be 0,
and if the value of key is INT_MIN then 0-INT_MIN could potentially
be INT_MAX+1 (2's complement system), but on 1's complement or
signed-magnitude then -INT_MIN is INT_MAX and no undefined behaviour
would have occured for those number systems

- if char is signed then its minimum value would be SCHAR_MIN
and that minus INT_MIN might exceed INT_MAX by abs(SCHAR_MIN)
or abs(SCHAR_MIN)+ 1 . But in this case, it would not just be the
key of value INT_MIN that leads to the undefined behaviour: it would
be any key between INT_MIN and INT_MIN-SCHAR_MIN that would lead
to arithmetic overflow on the subtraction.

On the other hand, once the subtraction is completed, the result
is being stored back into str[i] which is a char. If char is
signed then if the result of the subtraction is less than SCHAR_MIN
then the result of the store operation is undefined. If char
is unsigned then the result of the store operation *is* defined
no matter what the value of the subtraction was [unless the
subtraction result was undefined as per the above.]

In summary, if char is unsigned then there is undefined behaviour
in the case of key = INT_MIN on a 2s complement system, but no
undefined behaviour for 1s complement or signed magnitude;
The null terminator doesn't go through the loop in encrypt.
str[i] always has a non zero value in encrypt;
which is a positive value if char is unsigned.
If unsigned char gets promoted to signed int, as is likely,
and if key equals INT_MIN,
then the result of the subtraction will always excede INT_MAX,
regardless of 1s complement or signed magnitude.
if char is signed then there is a fair range of values of key
that will produce arithmetic overflow, and an even larger range of
values of key that will produce problems at the assignment operation
even if there was no arithmetic overflow.


--
pete
Jun 28 '06 #11

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
4123
by: Stephen Boulet | last post by:
I'm looking to install python on hpux 10.2. Anyone know of a site hosting a depot file of a recent python? Thanks. Stephen
1
1547
by: dirk dierickx | last post by:
All, I'm looking for a way to hide opened windows in X, these windows can be using any widget-set so it will not target gtk, qt, motif, etc directly (I know how to do it in gtk for example, but this will only work for gtk apps ofcourse). Just an easy way to select a certain window and hide it, is anything like this possible?
1
4143
by: Jorge | last post by:
All, I've got a process that creates some children and want to be alerted when they die. To do this, the SIGCHLD signal is registered in the process using sigaction to jump to a subprogram as soon as it's received. The problem comes when many children exit at the same time and their father seems to miss some of them. This happens quite often, but not always.
3
4676
by: Jeremy Lemaire | last post by:
Hello, I am working on cross platform code that is displaying a huge memory leak when compiled on 11.00 HPUX using the aCC -AA flag. It is not leaking on NT, LINUX, Solaris, or HPUX without the -AA flag. In another news group I came across some interesting (ok scarey) information regarding memory leaks in the STL list<...> container. I have compiled and executed the following code and verified that this does in fact leak on my system.
1
3644
by: smsabu2002 | last post by:
Hi, I am facing the build problem while installing the DBD-MySql perl module (ver 2.9008) using both GCC and CC compilers in HP-UX machine. For the Build using GCC, the compiler error is produced due to the unknown GCC compiler option "+DAportable". For the Build using CC, the preprocessor error is produced due to the recursive declration of macro "PerlIO" in perlio.h file.
4
2287
by: kongkolvyu | last post by:
Hi The strptime function works just fine on Solaris. Here is an example on how I use it: struct tm tmpTm; if(strptime("20010101010101","%Y%m%d%H%M%S",&tmpTm)==NULL) printf("Error,String convert to time Error\n"); On the HPUX platform, this call to strptime always returns NULL. Does anybody have an idea why this does not work.
1
2877
by: Jay Hamilton | last post by:
Hello, I am running into an invalid address alignment error on an HPUX box when I attempt to lookup a value in a STL map. The argument being passed in is a double, which is accessed from a structure; the map's key is also a double. The issue seemed to be occuring in the map's default comparison function so I implemented my own comparison operator, but then the error continued happening in my new fxn. Strangely, casting the double I...
0
2115
by: alokverma | last post by:
Hi all, I am trying to compile some code on HP-UX-Itanium faluire. using aCC: HP C/aC++ B3910B A.06.12 I have written a sample code below and using the following compilation command. *aCC -c -o test.o -AP -Ae -DHPUX test.cpp*
3
2334
by: amit2781 | last post by:
I am trying to build the my project on HPUX (HP-UX oscar B.11.11 U 9000/800 741028561 unlimited-user license) which access the Mysql library. But it is giving error as : Error : MySQL51/lib/hpux/libmysqld.a(client.o) - shared library must be position independent. Use +z or +Z to recompile. I am using this option in building: aCC -Wl,+s,-E,+vnocompatwarnings -z -g0 -b -Wl,-Bsymbolic. I also tried using the +Z, +z, also added...
0
9718
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9596
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10364
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10109
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7649
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6876
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5545
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4328
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3008
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.